Androidでインストール済みのアプリ一覧の取得方法
Androidでインストール済みのアプリ一覧の取得方法を調べました。
よくある、Webにあるインストール済みのアプリ一覧の取得方法ですが、
『Androidでのランチャーから起動出来るアプリの一覧の取得』
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public class ListLuncherActivity extends ListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); // リスト作成 ArrayList<String> appList = new ArrayList<String>(); // パッケージマネージャーの作成 PackageManager packageManager = getPackageManager(); // ランチャーから起動出来るアプリケーションの一覧 Intent intent = new Intent(Intent.ACTION_MAIN, null ); intent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> appInfo = packageManager.queryIntentActivities(intent, 0 ); // アプリケーション名の取得 if (appInfo != null ) { for (ResolveInfo info : appInfo) { appList.add( (String)info.loadLabel(packageManager)); } } // リスト表示設定 ArrayAdapter<String> adapter = new ArrayAdapter<String>( this , android.R.layout.simple_list_item_1, appList); setListAdapter(adapter); } } |
これがやりたいことでは無い…、インストールしている全てのアプリケーションの情報が取得したい。
で、色々と調べてわかった事は以下のような方法があった。
『Androidでのインストールしているアプリケーションの一覧の取得』
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public class ListInstallActivity extends ListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); // リスト作成 ArrayList<String> appList = new ArrayList<String>(); // パッケージマネージャーの作成 PackageManager packageManager = getPackageManager(); // インストール済みのアプリケーション一覧の取得 List<ApplicationInfo> applicationInfo = packageManager.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo info : applicationInfo) { appList.add((String)packageManager.getApplicationLabel(info)); } // リスト表示設定 ArrayAdapter<String> adapter = new ArrayAdapter<String>( this , android.R.layout.simple_list_item_1, appList); setListAdapter(adapter); } } |
これで、本当のインストール済みアプリの一覧の取得が出来るようになりました。
ですが、プリインストールアプリがあるので、スゴイ邪魔なので次の1行を追加
1 | if ((info.flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo.FLAG_SYSTEM) continue ; |
起動しているアプリ自体が一覧に表示されるのでそれも、表示させないようにしたい場合は、
1 | if (info.packageName.equals( this .getPackageName())) continue ; |
これで自分自身も含まれないように出来ます。
これで、インストール済みアプリの一覧の取得が出来るようになりました。