Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Intents and Broadcast Receivers Implicit Intents and Intent Filters Unmatched Implicit Intents

Boban Talevski
Boban Talevski
24,793 Points

Provided error handling sample code doesn't seem to work for me with API 27 and AS 3.0+

This doesn't seem to work

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);
}

I'm just getting another snackbar with the "Sorry..." message from the code above.

So, I modified the code like this

Uri googlePlayUri = Uri.parse("http://play.google.com/store/search?q=maps&c=apps");
Intent googlePlayIntent = new Intent(Intent.ACTION_VIEW);
googlePlayIntent.setData(googlePlayUri);

if (googlePlayIntent.resolveActivity(getPackageManager()) == null) {
    Snackbar.make(rootLayout, "Sorry, nothing found to handle this request.", Snackbar.LENGTH_LONG).show();
    }
else {
    startActivity(googlePlayIntent);
}

One of the reasons was changing the way implicit intent is created, so instead of using an empty constructor and putting an Extra with the action and uri, I did it the same way as was described in the course with the previous intent. Add the intent action in the constructor, and add the Uri with setData instead of putExtra.

The other issue was that even after doing the above, I still couldn't get it to work using the "market://..." version of the Uri (maybe because the emulator doesn't have google play?). So I had to change the Uri to a classic browser version "http://..." and then it worked (with the google maps app still disabled of course), it opened the default browser with map applications from the google play store.

Just letting everyone know if they try using the sample code and stumble upon these issues. And maybe Ben Jakuben can update the code in the teacher's notes as well :).