Created
September 25, 2016 21:26
-
-
Save luckyhandler/69460f2a4d014a3113e674f2f3f1fa55 to your computer and use it in GitHub Desktop.
Android - Start Browser
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
| public static void startBrowser(@NonNull final Context context, @NonNull final String url, @Nullable final Bundle animationBundle) { | |
| final String preparedUrl = trimUrl(url); | |
| final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(preparedUrl)); | |
| browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
| context.startActivity(browserIntent, animationBundle); | |
| } | |
| private static String trimUrl(final String url) { | |
| String toReturn = url; | |
| if (!url.startsWith("http://") && !url.startsWith("https://")) { | |
| toReturn = "http://" + url; | |
| } | |
| if (url.endsWith("/")) { | |
| toReturn = url.substring(0, url.length() - 1); | |
| } | |
| return toReturn; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment