Created
April 7, 2016 05:15
-
-
Save Ray33/d034fc39234c38614289b5a88cf40e4b to your computer and use it in GitHub Desktop.
Open chrome app with a given link, if user doesn't have chrome, will open with other browser app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://someurl.com")); | |
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
//Give chrome browser a priority , if exist, otherwise, returns other browser package | |
final String browserPackage = ActivityUtils.getBrowserPackage(intent, this); | |
if (!browserPackage.isEmpty()) { | |
intent.setPackage(browserPackage); | |
} | |
try { | |
startActivity(intent); | |
} catch (ActivityNotFoundException ex) { | |
// Chrome browser presumably not installed so allow user to choose instead | |
intent.setPackage(null); | |
startActivity(intent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment