10
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Intentに対応したパッケージ情報色々取得!

Posted at

Androidの暗黙的インテントはとても便利です

でも、選択ダイアログをカスタマイズする必要が出たのでその時のメモ

パッケージリスト取得

今回は ACTION_SENDに対応するパッケージリストを取得します

List
  PackageManager pm = mActivity.getPackageManager();  
  Intent intent = new Intent( Intent.ACTION_SEND );  
  intent.setType("text/plain");  
  List<ResolveInfo> resolve = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);  		

これで resolveリストが取得できました
あとはこの中から必要なデータを抽出

パッケージ名

package
  for( ResolveInfo info: resolve){
    ActivityInfo activityinfo = info.activityInfo;  
    Log.d( "package name", activityinfo.packageName);
  }

アクティビティー名 (この場合は ACTION_SENDを受け取るアクティビティー名)

package
  for( ResolveInfo info: resolve){
    ActivityInfo activityinfo = info.activityInfo;  
    Log.d( "activity name", activityinfo.name);
  }

アイコン

icon
  Bitmap bmp = ((BitmapDrawable)pm.getApplicationIcon( pkgname )).getBitmap();
  ByteArrayOutputStream ost;
  bmp.compress (Bitmap.CompressFormat.PNG, 100, ost );
  byte[] b = ost.toByteArray();
		ret = ost.toByteArray();
10
12
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
10
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?