/**
* 查询手机内所有支持分享的应用
* @param context
* @return
*/
public static List<ResolveInfo> getShareApps(Context context){
List<ResolveInfo> mApps = new ArrayList<ResolveInfo>();
Intent intent=new Intent(Intent.ACTION_SEND,null);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType("text/plain");
PackageManager pManager = context.getPackageManager();
mApps = pManager.queryIntentActivities(intent,PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
return mApps;
}
由于该方法,返回的并不是 PackageInfo 对象。而是 ResolveInfo。因此获取图片、应用名、包名的方法不一样,如下:
PackageManager pManager = MessageSendActivity.this.getPackageManager();
/*********************查询手机内所有支持分享的应用*********************/
List<ResolveInfo> resolveList = Utils.getShareApps(MessageSendActivity.this);
for(int i=0;i<resolveList.size();i++) {
ResolveInfo resolve = resolveList.get(i);
ShareItemInfo shareItem = new ShareItemInfo();
//set Icon
shareItem.setIcon(resolve.loadIcon(pManager));
//set Application Name
shareItem.setLabel(resolve.loadLabel(pManager).toString());
//set Package Name
shareItem.setPackageName(resolve.activityInfo.packageName);
}
总结:
通过 PackageInfo 获取具体信息方法:
包名获取方法:packageInfo.packageName
icon获取获取方法:packageManager.getApplicationIcon(applicationInfo)
应用名称获取方法:packageManager.getApplicationLabel(applicationInfo)
使用权限获取方法:packageManager.getPackageInfo(packageName,PackageManager.GET_PERMISSIONS)
.requestedPermissions
通过 ResolveInfo 获取具体信息方法:
包名获取方法:resolve.activityInfo.packageName
icon获取获取方法:resolve.loadIcon(packageManager)
应用名称获取方法:resolve.loadLabel(packageManager).toString()