1.在AndroidManifest.xml中定义shceme:
<activity
android:name="..SchemeActivity" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!--协议定义-->
<data android:scheme="如http" />
</intent-filter> </activity>
2.解析:
public class SchemeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initIntent();
}
private void initIntent() {
Uri uri = Uri.parse(getIntent().getDataString());
//获取param
String id = uri.getQueryParameter("id");
String typeStr = uri.getQueryParameter("type");
Intent intent ;
switch (typeStr) {
case "0":
//处理
break;
default:
break;
}
startActivity(intent);
finish();
}
}