Reputation: 17185
I have a button that the user can click which sends them to the app page in the Google Play store. This is the code I use for the button:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.problemio"));
startActivity(intent);
and the package is here: https://play.google.com/store/apps/details?id=com.problemio
and sometimes it works fine, but sometimes I get a crash report like this:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=com.problemio }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
at android.app.Activity.startActivityForResult(Activity.java:2833)
at android.app.Activity.startActivity(Activity.java:2959)
at com.problemio.content.BusinessIdeasActivity$5.onClick(BusinessIdeasActivity.java:107)
at android.view.View.performClick(View.java:2538)
at android.view.View$PerformClick.run(View.java:9152)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)
Any idea why it only sometimes works?
Thanks!
Upvotes: 3
Views: 1819
Reputation: 23498
I would try a bit different URL for your software:
Uri uri = Uri.parse("market://search?q=pname:com.problemio");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
try {
this.startActivity(intent);
} catch (ActivityNotFoundException anfe) {
// Hmm, market is not installed
Log.w(TAG, "Android Market is not installed");
}
Upvotes: 5
Reputation: 52936
This would happen on devices that don't have the Android Market/Google Play installed. There are actually quite a few of those, especially cheapish tablets. You can catch the exception of check if the market/play app is installed to prevent this from happening.
BTW, if you are only distributing on the Market/Play Store, your app might have been pirated, or maybe someone just took it off their rooted device and pushed it on their new el cheapo tablet or the emulator.
Upvotes: 3
Reputation: 34765
try{
Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse("https://market.android.com/details?id=com.problemio"));
startActivity(viewIntent);
}catch (ActivityNotFoundException activityException) {
Log.e("helloandroid", "Call failed",activityException);
}
try this, now your app wont crash but may have exception.
Upvotes: 1