android手机分享app,Android -- 查询手机上所有的能分享图片或者文字的App packageName...

//方法一 查找分享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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值