首页 > 解决方案 > 从android中的webview打开(启动)instagram应用程序的延迟

问题描述

我尝试使用以下代码同时打开 instagram 和 whatsapp。

Java 代码:

    mywebView.setWebViewClient(new WebViewClient() {

            @Override
            public boolean shouldOverrideUrlLoading(WebView wv, String url) {
                if(url.startsWith("tel:") || url.startsWith("whatsapp:")) {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(url));
                    startActivity(intent);
                    return true;
                }
                else if(url.startsWith("intent://instagram.com")){
                    Uri uri = Uri.parse("http://instagram.com/_u/user_id");
                    Intent insta = new Intent(Intent.ACTION_VIEW, uri);
                    insta.setPackage("com.instagram.android");
                    startActivity(insta);
                    startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("http://instagram.com/user_id")));

                }
                return false;
            }
        });

单击 webview 中的 Instagram 链接后,我看到 Image1 :在此处输入图像描述

单击右上角的打开应用程序后,我会在 Instagram 自动打开之前得到一两秒钟。为了不获得第二张图片,我应该进行哪些更改?: 在此处输入图像描述

标签: androidwebviewandroid-webview

解决方案


添加return true; instagram 意图并删除

startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("http://instagram.com/user_id")));

更新代码:-

else if(url.startsWith("intent://instagram.com")){
                    Uri uri = Uri.parse("http://instagram.com/_u/user_id");
                    Intent insta = new Intent(Intent.ACTION_VIEW, uri);
                    insta.setPackage("com.instagram.android");
                    startActivity(insta);
                    //startActivity(new Intent(Intent.ACTION_VIEW Uri.parse("http://instagram.com/user_id"))); // remove this line
                    return true; 
                }

推荐阅读