share分享功能过滤

http://www.eoeandroid.com/forum.php?mod=viewthread&tid=113258

 获取可以使用share功能的程序

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;
        }


打包成list
private List<ResolveInfo> resolveList;

        private PackageManager pManager;

        protected List<Map<String, Object>> getNoteData() {
            List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
            Map<String, Object> map;
            pManager = this.anchor.getContext().getPackageManager();
            resolveList = getShareApps(this.anchor.getContext());

            if (resolveList == null) {
                 return null;

            } else {
                int length = resolveList.size();
                for (int i = 0; i < length; i++) {
                    ResolveInfo resolve = resolveList.get(i);
                    map = new HashMap<String, Object>();

                      // 更多可获取的信息,参考前面的文章
                    map.put("title", resolve.loadLabel(pManager).toString());
                    map.put("img", resolve.loadIcon(pManager));     // 如果使用listview,这个地方无效,需要直接在getView里面设置
                    list.add(map);
                }
            }
            return list;
        }

上面的那个list放入listview,单击每个item后处理:
listView.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    if (resolveList != null && pManager != null) {
                        ResolveInfo resolve = resolveList.get(arg2);
                        Intent it = new Intent(Intent.ACTION_SEND);
                        it.setPackage(resolve.activityInfo.packageName);
                        it.putExtra(Intent.EXTRA_TEXT, "Custom Text");
                        it.setType("text/plain");
                        anchor.getContext().startActivity(it);

                    }

                }

            });

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值