LoginSignup
0
0

More than 1 year has passed since last update.

androidメモ

Last updated at Posted at 2022-10-08

審査がある。

15年ごろの3分が 22年では2日に伸びている。

packageName一覧を列挙する

Intent i = getIntent();
pm.getLaunchIntentForPackage("package.name.xxxxx");
@SuppressLint("QueryPermissionsNeeded") List<ResolveInfo> resolve = pm.queryIntentActivities(i, PackageManager.MATCH_ALL);
for (ResolveInfo s : resolve) {
    Log.d("IconResourceID", String.valueOf(s.getIconResource()));
}

アプリが入っていない場合にストアへ飛ばす

try {
    startActivity(intent);
} catch (Exception ignored) {
    // todo: 事前のinstall検証でもいいかもしれない
    try {
        Intent googlePlayIntent = new Intent(Intent.ACTION_VIEW);
        googlePlayIntent.setData(Uri.parse("market://details?id=a.b.c.d"));
        startActivity(googlePlayIntent);
    } catch (Exception ActivityNotFoundException) {
    }
}

指定パッケージを開く

Manifestにqueryを指定する必要が11以降で発生
https://www.gesource.jp/weblog/?p=8537

drawableが22からCompat経由

// 指定している全てのアプリを出そうとするが、入っていない場合もあるため、デフォルトのアイコンを指定
Resources res = getResources();
Drawable icon = ResourcesCompat.getDrawable(res, R.drawable.png, null);
Boolean hasPackage = true;

http://www.syo-app.com/archives/1545795.html
https://developer.android.com/guide/topics/graphics/drawables?hl=ja#java

0
0
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
0
0