Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Implicit Intent
public static final String TAG = "ImplicitIntentsActivity";
public void openUrlInBrowser(String url) {
// Parse the URI and create the intent
Uri website = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, website);
// Find an activity to hand the intent and start that activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.e(TAG, getResources().getString(R.string.can_not_handle_open_url));
}
}
public void openLocationInMaps(String location) {
// Parse the location and create the intent.
Uri addressUri = Uri.parse("geo:0,0?q=" + location);
Intent intent = new Intent(Intent.ACTION_VIEW, addressUri);
// Find an activity to handle the intent, and start that activity.
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.e(TAG, getResources().getString(R.string.can_not_handle_open_location));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment