-1

打开我试图打开已URL扩展的.cmsCMS网址而非浏览器通过隐含的意图

尝试简单的网址,而不是当如新闻提要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) 
+0

该链接完美使用intent for me ..这是你试过的操作系统版本? – Anonymous

+0

Android奥利奥8.0和棉花糖6.0 – VVB

+1

我厌倦了奥里多8.0,它工作得很好。 – Anonymous

回答

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); 
} 
+0

不。在这样做,我得到的消息“网站无法到达”,它确实是通过复制粘贴相同的网址在浏览器上打开罚款。如果条件导致url损坏 – VVB

+0

我猜测是这是不是代码问题..我想你的DNS或类似的东西有一些问题。尝试添加硬编码的URL作为URL并检查。 – Anonymous

+0

没有但在手机浏览器中复制了相同的网址并且可以使用 – VVB