I have written a code to list all the installed apps. I have a button event which will be redirected to the particular App home page in the Google Store. However I am unable to successfully redirect them. Here is the code I have employed. I am not getting the app's package name in the uri and hence I am getting "URL not found on the server". Kindly drop in your valuable suggestions.
public void update(View view) {
Context context = this;
Uri uri = Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
// To count with Play market backstack, After pressing back button,
// to taken back to our application, we need to add following flags to intent.
try {
startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName())));
}
}
Thanks in advance
To Open a Native Play store page you must use this play store schema
market://details?id=your.app.package.name
But keep in mind that may be the device doesn't have Google play services or the play store itself.
So to avoid crashing, catch the exception happened and try to open the normal URL
public static void openPlayStorePage(Activity parentActivity, String targetPackageName) {
try {
parentActivity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + targetPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
parentActivity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + targetPackageName)));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With