android.content.pm パッケージの
PackageManagerクラスの
"queryIntentActivities (Intent intent, int flags)"
で取得できます。
こんな感じ
- PackageManager pm = getPackageManager();
- List<resolveinfo> resolveInfo = pm.queryIntentActivities(new Intent(Intent.ACTION_SEARCH), PackageManager.MATCH_DEFAULT_ONLY);
- StringBuffer sb = new StringBuffer();
- for(int i = 0; i < resolveInfo.size(); i++) {
- ResolveInfo info = resolveInfo.get(i);
- ActivityInfo activityinfo = info.activityInfo;
- sb.append(activityinfo.packageName + "\n");
- }
- textView.setText(sb.toString());
- </resolveinfo>
ACTION_SEND などは、setType() しないと
パッケージが引っかかりません。
なので、こんな感じで
- PackageManager pm = getPackageManager();
- Intent intent = new Intent(Intent.ACTION_SEND);
- intent.setType("text/plain");
- List<resolveinfo> resolveInfo = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
- </resolveinfo>
さらにさらに、
とってきた activity の一覧をソートするには
"Collections" と "ResolveInfo.DisplayNameComparator"
を使います。
こんな感じ
- // sort
- Collections.sort(resolveInfo, new ResolveInfo.DisplayNameComparator(pm));
Inflator を使って TableLayout にしました。
ソースとアプリも公開しちゃいます。
GetIntentList.apk
GetIntentList.zip
参考ページ
・http://developer.android.com/intl/ja/reference/android/content/pm/PackageManager.html#queryIntentActivities(android.content.Intent, int)
・http://developer.android.com/intl/ja/guide/topics/intents/intents-filters.html#imatch
0 件のコメント:
コメントを投稿