我正在尝试打开网址扩展名为.cms的新闻提要
相反,当尝试简单的 url(例如 http://www.google.com/)时,它按预期工作,但不适用于 .cms 页面。
我不想添加自己的 Web 视图。我很确定.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)
由于某些原因,您的网址可能使用了"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);
}