您可以使用market://
prefix来做到这一点.
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")))
}
我们在这里使用try/catch
块,因为如果目标设备上没有安装Play Store,将抛出Exception
块.
NOTE:任何应用程序都可以注册为能够处理market://details?id=<appId>
个Uri,如果你想专门针对Google Play,请查看Berťák答案