CopyPastor

Detecting plagiarism made easy.

Score: 1.7066164016723633; Reported for: String similarity, Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2016-08-16
by Riyaz Parasara

Original Post

Original - Posted on 2012-08-01
by Cat



            
Present in both answers; Present only in the new answer; Present only in the old answer;

you can do using the market:// prefix please use my sample code read carefully and add your application package name

final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); } catch (android.content.ActivityNotFoundException anfe) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName))); }

We use a try/catch block here because an Exception will be thrown if the Play Store is not installed on the target device.
You can do this using the [`market://` prefix](https://developer.android.com/distribute/tools/promote/linking.html).
## Java
final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); } catch (android.content.ActivityNotFoundException anfe) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName))); }
## Kotlin
try { startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$packageName"))) } catch (e: ActivityNotFoundException) { startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$packageName"))) }
We use a `try/catch` block here because an `Exception` will be thrown if the Play Store is not installed on the target device.
**NOTE**: any app can register as capable of handling the `market://details?id=<appId>` Uri, if you want to specifically target Google Play check the *Berťák* answer

        
Present in both answers; Present only in the new answer; Present only in the old answer;