最近寫的項目中涉及外部瀏覽器以及項目webview中調起app,所以總結下,和大家分享下。
總的實現方法還是比較簡單的,
1:在清單中注冊
首先在AndroidManifest文件中,注冊一個過濾器
<intent-filter >
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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="xxx" android:host="xxx"/>
</intent-filter>
其中scheme和host如下:
scheme://host:port/path
例如:nearbar://com.nearbar.android:200/folder/subfolder/etc
\---------/ \---------------------------/ \---/ \--------------------------/
scheme host port path
\--------------------------------/
authority
2:在mainactivity中接收
if (Intent.ACTION_VIEW.equals(action)) {
Uri uri = i_getvalue.getData();
String data = uri.toString();
}
由於我的項目中url中傳過來的是json串,通過解析來判斷具體的操作。