Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
When using implicit intents, we are trusting that something in the system will be there to handle the intent. We should be defensive and add an error check, and, if we're really nice, guide the user to a solution.
Below is some example code for how to take a user to Google Play to download an app that can handle a specific kind of Intent. For more information, check out Linking to Your Products on the Android Developer site.
Uri googlePlayUri = Uri.parse("market://search?q=map");
Intent googlePlayIntent = new Intent();
googlePlayIntent.putExtra(Intent.ACTION_VIEW, googlePlayUri);
if (googlePlayIntent.resolveActivity(getPackageManager()) == null) {
Snackbar.make(mRootLayout, "Sorry, nothing found to handle this request.", Snackbar.LENGTH_LONG).show();
}
else {
startActivity(googlePlayIntent);
}
Downloads
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up