CMS网址无法通过隐式意图在浏览器中打开

时间:2017-10-10 04:38:22

标签: android android-intent android-webview activitynotfoundexception android-implicit-intent

我正在尝试打开包含网址扩展名.cms

的新闻Feed

相反,当尝试简单的网址时,例如http://www.google.com/,它按预期工作,但不适用于.cms页面。

我不想添加自己的WebView。我很确定.cms会导致问题,但不知道如何使用现成的/第三方浏览器来解决它。

public static void openLinkInExternalBrowser(Context context, String url) {
  Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
   context.startActivity(browserIntent);
}

当我尝试打开它时,我会遇到异常

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat= http://timesofindia.indiatimes.com/india/spurned-lovers-tip-off-helped-track-kill-top-jaish-terrorist-khalid/articleshow/61013573.cms  }
                                                                 at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1936)
                                                                 at android.app.Instrumentation.execStartActivity(Instrumentation.java:1615)
                                                                 at android.app.Activity.startActivityForResult(Activity.java:4471)
                                                                 at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:54)
                                                                 at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
                                                                 at android.app.Activity.startActivityForResult(Activity.java:4429)
                                                                 at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:708)
                                                                 at android.app.Activity.startActivity(Activity.java:4788)
                                                                 at android.app.Activity.startActivity(Activity.java:4756)
                                                                 at adapters.NewsAdapter$1.onClick(NewsAdapter.java:66)
                                                                 at android.view.View.performClick(View.java:6219)
                                                                 at android.view.View$PerformClick.run(View.java:24482)
                                                                 at android.os.Handler.handleCallback(Handler.java:769)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:98)
                                                                 at android.os.Looper.loop(Looper.java:164)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

1 个答案:

答案 0 :(得分:0)

由于某些原因,您的网址可能一直在使用" www"。因此尝试用" http"或者" https"。这对我现在有用。

public static void openLinkInExternalBrowser(Context context, String url) {
    if (!url.startsWith("https://") && !url.startsWith("http://")){ 
        url = "http://" + url; 
    }
   Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
   context.startActivity(browserIntent);
}