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