LoginSignup
26
25

More than 5 years have passed since last update.

Playストアアプリを起動する&アプリがインストールされているかチェックする

Posted at

アプリ内からパッケージを指定して、Playストアアプリを起動させる方法です。

public void execPlayApp(Context context, String targetPackage) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + targetPackage));
        try {
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

さらに、起動したいアプリがインストールされているかをチェックすれば、アプリがインストールされていない時は、Playストアに飛ばすこともできますね。

public boolean isInstall() {
        try {
            // パッケージ名を指定してインストール状況をチェック
            PackageManager packageManager = this.getPackageManager();
            ApplicationInfo applicationInfo = packageManager.getApplicationInfo(TARGET_PACKAGE, PackageManager.GET_META_DATA);
            if (applicationInfo != null) {
                return true;
            }
        } catch (NameNotFoundException exception) {
            return false;
        }

        return false;
    }
26
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
25