Androidでインストール済みのアプリ一覧の取得する方法。googleTTSがインストールされているのかどうかをチェックする必要があった。インストールされてなかったら文章の読み上げツールが使えなくなるのでインストールさせるようにするということが必要だった。
ArrayList<String> appList = new ArrayList<String>();
// パッケージマネージャーの作成
PackageManager packageManager = getPackageManager();List<ResolveInfo> appInfo = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
// アプリケーション名の取得
for (ApplicationInfo info : applicationInfo) {
//プリインストールアプリを除外
if ((info.flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo.FLAG_SYSTEM) continue;
//自アプリを除外
if (info.packageName.equals(this.getPackageName())) continue;
//配列にアプリを追加
appList.add((String)packageManager.getApplicationLabel(info));
}