「その他のアプリ」というボタンを使用して、Play ストアのアプリのリストにアクセスしたいと考えています。これはページのリンクです:
https://play.google.com/store/apps/developer?id=Jouni
??
「その他のアプリ」というボタンを使用して、Play ストアのアプリのリストにアクセスしたいと考えています。これはページのリンクです:
https://play.google.com/store/apps/developer?id=Jouni
??
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://」URI をどのアプリでも処理できない場合も処理するこのソリューションを思いつきました。この場合、フォールバックとして 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);
}
}
ボタンの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);