0

I was wondering if there is a way to force open chrome from android webview (with js, php) to a specific URL?

To clarify, if someone clicks the said link in an app with webview activity (ex. Skype mobile), the link will cause chrome launch to the link instead of webview activity (or even first launches webview activity and then moves to chrome).

I know I can detect if client is webview by checking for substring "version" in the UA string, but I am unfamiliar with any way to deliberately launch a specific browser from URL or js.

Thanks in advance!

1 Answers1

0

Yes you can do it this way, in android:

String url = "https://google.com";
try {
    Intent i = new Intent("android.intent.action.MAIN");
    i.setComponent(ComponentName.unflattenFromString("com.android.chrome/com.android.chrome.Main"));
    i.addCategory("android.intent.category.LAUNCHER");
    i.setData(Uri.parse(url));
    startActivity(i);
}
catch(ActivityNotFoundException e) {
    // Chrome is not installed
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(i);
}
Ashwani
  • 1,294
  • 1
  • 11
  • 24
  • assume I have no control over the android code. is there a way to do this with JS/php? – Michael Emmet Apr 23 '18 at 11:48
  • you are using which framework, if it is hybrid please let us know...and add it to your question too... – Ashwani Apr 23 '18 at 11:49
  • and yes it is possible...wait leme write a quick hack for you – Ashwani Apr 23 '18 at 11:49
  • 1
  • This is not an android development question because I have no control over the app's code, therefore I must use web programming languages (such as js, php, whatever is required). – Michael Emmet Apr 23 '18 at 11:57
  • [please check this, looks not like possible](https://stackoverflow.com/questions/45953870/how-to-force-links-or-pages-to-open-outside-of-facebook-inapp-browser?rq=1) – Beny Apr 23 '18 at 12:04
  • i amnot able to understand...are you using InAppBrowser plugin?.. in your url you must be writing something like _blank or _self... instead of that you can write _system, it will open system browser if iOS it will open safari and if android it will open Chrome or other browser – Ashwani Apr 23 '18 at 12:24