联系我们 - 广告服务 - 联系电话:
您的当前位置: > 关注 > > 正文

全球快消息!如何查询appInfo、appName?appInfo查询方法

来源:CSDN 时间:2023-03-17 10:35:56

//方法一 查找分享app class name

public static Map getShareList(final Activity mActivity)


(资料图)

{

final Map appInfo = new HashMap();

List appList = getShareTargets(mActivity);

String[]items = null;

if(appList.size()>0)

{

for(int i = 0; i < appList.size(); i++)

{

ResolveInfo tmp_ri = (ResolveInfo)appList.get(i);

ApplicationInfo apinfo = tmp_ri.activityInfo.applicationInfo;

String tmp_appName = apinfo.loadLabel(mActivity.getPackageManager()).toString();

if(tmp_appName.equals("信息"))

{

appInfo.put(tmp_appName, tmp_ri);

}//imgIds = {R.drawable.e_address_book, R.drawable.e_weibo, R.drawable.e_weixin};

if(tmp_appName.equals("微博"))

{

appInfo.put(tmp_appName, tmp_ri);

}

if(tmp_appName.equals("微信"))

{

appInfo.put(tmp_appName, tmp_ri);

}

}

}

return appInfo;

}

public static List getShareTargets(Activity activity)

{

Intent intent=new Intent(Intent.ACTION_SEND,null);

intent.addCategory(Intent.CATEGORY_DEFAULT);

intent.setType("image/*"); //text/plain

PackageManager pm = activity.getPackageManager();

return pm.queryIntentActivities(intent,PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);

}

//方法二

public static boolean isShareAvaiable(Context context, String name) {

Intent intent = new Intent(); // 创建分享图片的意图

intent.setAction("android.intent.action.SEND");

intent.setType("image/*");

// 通过PackageManager查询到所有的能分享图片的Acitivity

List resolveInfos = ((Activity) context)

.getPackageManager().queryIntentActivities(intent,

PackageManager.GET_RESOLVED_FILTER);

List activityInfos = new ArrayList();

for (ResolveInfo resolveInfo : resolveInfos) {

ActivityInfo activityInfo = resolveInfo.activityInfo;

if (null != activityInfo) {

String activityName = activityInfo.name;

String packageName = activityInfo.packageName;

if (null != packageName) {

// 通过包名对比判断是否相应的程序

if (packageName.equals(name)) {

if (!TextUtils.isEmpty(activityName)) {

activityInfos.add(resolveInfo);

}

}

}

}

}

if (activityInfos.size() > 0) {

return true;

}

return false;

}

责任编辑:

标签:

相关推荐:

精彩放送:

新闻聚焦
Top