我写了一段代码来列出所有已安装的应用程序。我有一个按钮事件,它将被重定向到 Google 商店中特定的应用程序主页。但是我无法成功重定向它们。这是我使用的代码。我没有在 uri 中获取应用程序的包名称,因此我得到了“在服务器上找不到 URL”。请提出您的宝贵建议。
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())));
}
}
提前致谢
最佳答案
要打开 Native Play 商店页面,您必须使用此 Play 商店架构
market://details?id=your.app.package.name
但请记住,该设备可能没有 Google Play 服务或 Play 商店本身。
所以为了避免崩溃,捕获发生的异常并尝试打开正常的 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)));
}
}
关于Android App Play 商店重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33118724/