我已经打开谷歌播放商店使用以下代码
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse("https://play.google.com/store/apps/details?id=my packagename "));
startActivity(i);.
但它向我显示了一个完整的操作视图,以选择选项(浏览器/播放商店)。我需要直接在Play Store打开应用程序。
我已经打开谷歌播放商店使用以下代码
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse("https://play.google.com/store/apps/details?id=my packagename "));
startActivity(i);.
但它向我显示了一个完整的操作视图,以选择选项(浏览器/播放商店)。我需要直接在Play Store打开应用程序。
当前回答
你可以使用market://前缀来做到这一点。
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)));
}
科特林
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没有安装在目标设备上,则会抛出异常。
注意:任何应用程序都可以注册为能够处理市场://details?id = < appId > URI。如果你想特别针对谷歌Play, Berťák的答案中的解决方案是一个很好的替代方案。
其他回答
试试这个
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.example.android"));
startActivity(intent);
对于费率应用:重定向到播放商店。 在Flutter中,你可以通过这样的平台通道进行操作
颤振部分:
static const platform = const MethodChannel('rateApp'); // initialize
onTap:平台。invokeMethod('urls', {'android_id': 'com.xyz'}),
现在Android原生部分(Java):
private static final String RATEAPP = "rateApp"; // initialize variable
//现在在ConfigureFlutterEngine函数中:
new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), RATEAPP)
.setMethodCallHandler(
(call, result) -> {
if (call.method.equals("urls") && call.hasArgument("android_id")) {
String id = call.argument("android_id").toString();
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("$uri" + id)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + id)));
}
result.success("Done");
} else {
result.notImplemented();
}
}
);
你可以:
final Uri marketUri = Uri.parse("market://details?id=" + packageName);
startActivity(new Intent(Intent.ACTION_VIEW, marketUri));
在这里获取参考资料:
你也可以尝试这个问题公认答案中描述的方法: 无法确定谷歌播放商店是否安装在Android设备上
由于官方文档使用https://而不是market://,这结合了Eric和M3-n50的答案和代码重用(不要重复你自己):
Intent intent = new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName()));
try {
startActivity(new Intent(intent)
.setPackage("com.android.vending"));
} catch (android.content.ActivityNotFoundException exception) {
startActivity(intent);
}
如果GPlay应用程序存在,它会尝试打开GPlay应用程序,然后退回到默认状态。
人们,不要忘记你实际上可以从中得到更多的东西。我指的是UTM跟踪。https://developers.google.com/analytics/devguides/collection/android/v4/campaigns
public static final String MODULE_ICON_PACK_FREE = "com.example.iconpack_free";
public static final String APP_STORE_URI =
"market://details?id=%s&referrer=utm_source=%s&utm_medium=app&utm_campaign=plugin";
public static final String APP_STORE_GENERIC_URI =
"https://play.google.com/store/apps/details?id=%s&referrer=utm_source=%s&utm_medium=app&utm_campaign=plugin";
try {
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse(String.format(Locale.US,
APP_STORE_URI,
MODULE_ICON_PACK_FREE,
getPackageName()))).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse(String.format(Locale.US,
APP_STORE_GENERIC_URI,
MODULE_ICON_PACK_FREE,
getPackageName()))).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
}