-1

I am trying to open news feed which has url extension .cms

Instead when tried simple url e.g. http://www.google.com/, it works as expected but not for .cms page.

I don't want to add my own WebView. I am pretty sure that .cms is causing the problem but don't know how to resolve it with ready-made/third-party browser.

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

When I try to open it, I get below exception

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)
VVB
  • 7,363
  • 7
  • 49
  • 83

1 Answers1

0

For some reasons your url might have been using "www".So try to wrap it with either "http" or "https".This works for me now.

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);
} 
Sharath kumar
  • 4,064
  • 1
  • 14
  • 20
  • No. On doing so I get message "Site can't be reached" indeed it is opening fine on browser by copy pasting same url. if condition is causing url damage – VVB Oct 10 '17 at 05:12
  • What I am guessing is this is isn't code problem..I guess there is some problem with your dns or something like that.Try adding hardcoded url as url and check. – Sharath kumar Oct 10 '17 at 05:17
  • No but same url is copied in mobile browser and works – VVB Oct 10 '17 at 05:18