答案 0 :(得分:6)
启动Google Play商店可以正常使用一些市场URI:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(<market_uri>));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
uris可以在哪里
但是当您想要在欢迎页面上启动它时,无法正常工作,即当您只想启动指定应用ID或执行查询的Google Play商店时。
所以我提出了这个解决方案,它也处理了'market://'uris无法被任何应用程序处理的情况。在这种情况下,请使用Web浏览器作为后备。
这种解决方案并不是最好的,但它可以胜任。
public void launchPlayStore()
{
// look for intent able to process 'market://' uris
Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=dummy"));
PackageManager packageManager = getPackageManager();
ComponentName playStoreComponentName=null;
for(ResolveInfo resolveInfo : packageManager.queryIntentActivities(market, 0))
{
ActivityInfo activityInfo = resolveInfo.activityInfo;
String packageName = activityInfo.applicationInfo.packageName;
// lokking for "com.android.vending", "com.google.android.finsky.activities.MainActivity"
if (!packageName.contains("android"))// || !activityInfo.name.contains("android"))
continue;
// appname should be 'Play Store'
// String appName = resolveInfo.loadLabel(packageManager).toString();
playStoreComponentName = new ComponentName(packageName, activityInfo.name);
break;
}
if(playStoreComponentName!=null)
{
Intent intent = new Intent();
intent.setComponent(playStoreComponentName);
intent.setData(Uri.parse("market://"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_ANIMATION);
// launch Google Play Store app :-)
startActivity(intent);
}
else
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://play.google.com/"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_ANIMATION);
// fallback -> web browser
startActivity(intent);
}
}
答案 1 :(得分:1)
在按钮OnClick
中执行此操作String url = "https://play.google.com/store/apps/developer?id=Jouni";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);