AndroidManifest.xml 设置示例

    <activity android:name=".module.web.WebActivity">
        <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:host="page.sh"
                android:path="/webview"
                android:scheme="baiwanlu" />
        </intent-filter>
    </activity>

这样浏览器打开 baiwanlu://page.sh/webview 就可以唤起这个Activity,而App内跳转也可以通过隐式Intent

url 还可以跟参数 baiwanlu://page.sh/detail?id=767323

public static Intent getIntent(String url) {
    Intent intent;

    if (isNative(url)) {
        Uri uri = Uri.parse(url);
        intent = new Intent(Intent.ACTION_VIEW, uri);
        Set<String> params = uri.getQueryParameterNames();
        if (null != params) {
            for (String name : params) {
                intent.putExtra(name, uri.getQueryParameter(name));
            }
        }
    } else {
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("baiwanlu://page.sh/webview"));
        intent.putExtra(SHWebViewConstants.EXTRA_URL, url);
    }
    return intent;
}

标签: none

评论已关闭