WebView或浏览器通过Scheme调起App

WebView或浏览器通过Scheme调起App:

一、    在要调起的app中的AndroidManifes.xml文件中,在要被其它应用启动的Activity标签中添加如下拦截器:

<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="me.ricky.sample"
                android:path="/userDetails"
                android:port="8080"
                android:scheme="xieyi" />

可以只写一个host和scheme,如下:

<data
   
android:scheme="xieyi"

    android:host="me.ricky.sample"/>

 

例:

xieyi://me.ricky.sample/"

具体的配置及详情可见:

http://m.blog.csdn.net/litengit/article/details/74451989

注:引用litengit的文章

 

二、    在html页面中添加:

<a href="xieyi://me.ricky.sample/">打开appa>

 

例:写一个test.html页面(内容如下,)将此页面在浏览器中打开,点击“打开app”,就会跳转到app中;

test.html:

   

   

   

   

   

 

   

 

三、    通过webView打开app:

注意:在要打开其它app的应用中设置webVeiw:

private MyWebViewClient mWebViewClient = null;
mWebViewClient = new MyWebViewClient();

mWebView.setWebViewClient(mWebViewClient);

    private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            if (TextUtils.isEmpty(url)) return false;
            // 通过webView打开其它app
            try {
                if (!url.startsWith("http") || !url.startsWith("https") || !url.startsWith("ftp")) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    if (isInstall(intent)) {
                        getContext().startActivity(intent);
                        return true;
                    }
                }
            } catch (Exception e) {
                return false;
            }

            return false;
        }



        //判断app是否安装
        private boolean isInstall(Intent intent) {
            return MyApplication.getMyContext().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
        }
        // MyApplication.getMyContext()应当改成你自己对应的application


具体的配置及详情可见:

http://blog.csdn.net/u012452490/article/details/77931430

注:引用”恢兔子”的文章

 

最佳实践:以上亲测可以使用,我测了20多款浏览器,只有百度浏览器打不开,根据“恢兔子”所说,个人推测可能是百度浏览器屏蔽了此类调用。

你可能感兴趣的:(WebView或浏览器通过Scheme调起App)