1

I just wanted to "help" my users to give feedback to my app by providing a button to launch Market. Found a working solution here, of course, which does:

Uri uri = Uri.parse("market://details?id=<mypackagename>");
Intent intent = new Intent (Intent.ACTION_VIEW, uri); 
startActivity(intent);

Simple as that, thanks!

But: on my first run, I had that on my emulator. Gives an ActivityNotFoundException immediately.

Now, my question: is there a way to find out whether a call to this intent will succeed BEFORE I try it? That way I could hide the button completely to not even give the option.

Thanks for your much appreciated help!

Zordid
  • 10,451
  • 11
  • 42
  • 58
  • The answer to this question will give you what you need http://stackoverflow.com/questions/3341176/how-to-detect-the-existence-of-android-market-on-devices – Ollie C Sep 04 '11 at 15:23

3 Answers3

5

Instead of using this URL, you can use this one:

https://market.android.com/details?id=<mypackagename>

Even if the user doesn't have the Market application, he could go to the Website. If he has the Market application, he should have a prompt between Internet and Market. enter image description here

BTW, surround your code with a try catch in case he has nothing ;o)

Whiler
  • 7,998
  • 4
  • 32
  • 56
  • 1
    Yeah, that would work - but it does not look as nice as a direct jump... buuuuut, I could do this whenever I catch the exception! :) – Zordid Sep 04 '11 at 16:32
1

You can also use this method.

Instead of IMDB, use your market URL: market://details?id=&lt;mypackagename>

Community
  • 1
  • 1
Whiler
  • 7,998
  • 4
  • 32
  • 56
0

The exception was thrown just because there is no Android Market on the emulators. Every Android-powered device has the Android Market, so you shouldn't worry about this exception being thrown on a real device. Hope this helps.

Egor
  • 39,695
  • 10
  • 113
  • 130
  • Well, there are real devices without a market. Of course the chance they get my app is small, but it is not impossible! :) – Zordid Sep 04 '11 at 16:32