意图去玩商店?

A.J*_*A.J 0 android

我想要一个名为"更多应用"的按钮来访问我在Play商店中的应用列表.这是页面链接:

https://play.google.com/store/apps/developer?id=Jouni

??

Pas*_*cal 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);
Run Code Online (Sandbox Code Playgroud)

uris可以在哪里

  • 市场://细节ID =
  • 市场://搜Q =酒吧:

但是当您想要在欢迎页面上启动它时,它就不起作用了,即当您只想启动指定应用程序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);
    }
}
Run Code Online (Sandbox Code Playgroud)