获取分享android 系统分享列表 并调用app进行分享

http://www.zhihu.com/question/21288247





@Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        
        Intent shareIntent = new Intent();
        AppInfoVo appInfo = mAppInfoVos.get(position);
        shareIntent.setComponent(new ComponentName(appInfo.getPackageName(), appInfo.getLauncherName()));
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setType("image/*");
        //这里就是组织内容了,   
        shareIntent.putExtra(Intent.EXTRA_TEXT, "我正在使用菜急送" + mNet_address.getText());
        shareIntent.putExtra("Kdescription", "我正在使用菜急送" + mNet_address.getText()); //微信御用, 坑爹
        
        shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        File file = new File(mQRPicPath);
        if (file.exists()) {
            shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        }
        startActivity(shareIntent);
    }





  public List<AppInfoVo> getShareApps(Context context) {
        PackageManager packageManager = context.getPackageManager();
        List<AppInfoVo> appInfoVos = new ArrayList<AppInfoVo>();
        List<ResolveInfo> resolveInfos = new ArrayList<ResolveInfo>();
        Intent intent = new Intent(Intent.ACTION_SEND, null);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setType("text/plain");
        //      intent.setType("*/*");   
        PackageManager pManager = context.getPackageManager();
        resolveInfos = pManager.queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
        for (int i = 0; i < resolveInfos.size(); i++) {
            AppInfoVo appInfoVo = new AppInfoVo();
            ResolveInfo resolveInfo = resolveInfos.get(i);
            appInfoVo.setAppName(resolveInfo.loadLabel(packageManager).toString());
            appInfoVo.setIcon(resolveInfo.loadIcon(packageManager));
            appInfoVo.setPackageName(resolveInfo.activityInfo.packageName);
            appInfoVo.setLauncherName(resolveInfo.activityInfo.name);
            appInfoVos.add(appInfoVo);
        }
        return appInfoVos;
    }


  public class PropagandaAdapter extends BaseAdapter
    {
        private LayoutInflater inflater;
        
        @Override
        public int getCount() {
            return mAppInfoVos.size();
        }
        
        @Override
        public Object getItem(int position) {
            return mAppInfoVos.get(position);
        }
        
        @Override
        public long getItemId(int position) {
            return position;
        }
        
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (null == convertView) {
                if (null == inflater) {
                    inflater = LayoutInflater.from(parent.getContext());
                }
                convertView = inflater.inflate(R.layout.propaganda_list_layout, parent, false);
                ViewHolder holder = new ViewHolder();
                holder.tvPlatfromName = (TextView) convertView.findViewById(R.id.propaganda_share_to_list_tv_platform_name);
                holder.imgIcon = (ImageView) convertView.findViewById(R.id.propaganda_share_to_list_img_platform_icon);
                
                convertView.setTag(holder);
            }
            AppInfoVo appInfoVo = mAppInfoVos.get(position);
            ViewHolder holder = (ViewHolder) convertView.getTag();
            holder.tvPlatfromName.setText(appInfoVo.getAppName());
            holder.imgIcon.setImageDrawable(appInfoVo.getIcon());
            return convertView;
        }
        
        class ViewHolder
        {
            TextView tvPlatfromName;
            ImageView imgIcon;
        }
    }
    



package com.su.vegeshop.model.pojo;

import android.graphics.drawable.Drawable;

public class AppInfoVo {
    private Drawable icon;
    private String appName;
    private String packageName;
    private boolean isSystemApp;
    private long codesize;
    private String launcherName;
    
    
    public String getLauncherName() {
        return launcherName;
    }
    public void setLauncherName(String launcherName) {
        this.launcherName = launcherName;
    }
    public long getCodesize() {
        return codesize;
    }
    public void setCodesize(long codesize) {
        this.codesize = codesize;
    }
    public Drawable getIcon() {
        return icon;
    }
    public void setIcon(Drawable icon) {
        this.icon = icon;
    }
    public String getAppName() {
        return appName;
    }
    public void setAppName(String appName) {
        this.appName = appName;
    }
    public String getPackageName() {
        return packageName;
    }
    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }
    public boolean isSystemApp() {
        return isSystemApp;
    }
    public void setSystemApp(boolean isSystemApp) {
        this.isSystemApp = isSystemApp;
    }
    
}

 整个的Activity


public class PropagandaActivity extends BaseActivity implements AdapterView.OnItemClickListener, ShopModel.IShopStateListener
{
    private GridView mGridView;
    private ImageView mQrcodeImage;
    private List<AppInfoVo> mAppInfoVos = new ArrayList<AppInfoVo>();
    private PropagandaAdapter mPropagandaAdapter = new PropagandaAdapter();
    private ProgressDialog mProgressDialog;
    private Button mNet_address;
    private String mQRPicPath = "/sdcard/caijisong/";
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        onSetContentView(R.layout.propaganda_activity);
        
    }
    
    public static void start(Context context) {
        Intent intent = new Intent(context, PropagandaActivity.class);
        context.startActivity(intent);
    }
    
    @Override
    protected void initView() {
        mProgressDialog = new ProgressDialog(this);
        
        mNet_address = (Button) findViewById(R.id.net_address);
        mNet_address.append(BaseModel.sMobile);
        mQrcodeImage = (ImageView) findViewById(R.id.qrcode);
        mGridView = (GridView) findViewById(R.id.propaganda_gv_share_to);
        
    }
    
    @Override
    protected void initData() {
        mGridView.setAdapter(mPropagandaAdapter);
        ShopModel shopModel = new ShopModel(this);
        shopModel.getQrCode();
        PromptManager.showSimpleProgressDialog(mProgressDialog, "请稍后...");
        
        new AsyncTask<Void, Void, Void>()
        {
            
            @Override
            protected Void doInBackground(Void... arg0) {
                mAppInfoVos = getShareApps(mContext);
                return null;
            }
            
            protected void onPostExecute(Void result) {
                PromptManager.closeProgressDialog(mProgressDialog);
                mPropagandaAdapter.notifyDataSetChanged();
            };
        }.execute();
    }
    
    @Override
    protected void setListener() {
        mGridView.setOnItemClickListener(this);
    }
    
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        
        Intent shareIntent = new Intent();
        AppInfoVo appInfo = mAppInfoVos.get(position);
        shareIntent.setComponent(new ComponentName(appInfo.getPackageName(), appInfo.getLauncherName()));
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setType("image/*");
        //这里就是组织内容了,   
        shareIntent.putExtra(Intent.EXTRA_TEXT, "我正在使用菜急送" + mNet_address.getText());
        shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        File file = new File(mQRPicPath);
        if (file.exists()) {
            shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        }
        startActivity(shareIntent);
    }
    
    @Override
    public void onShopStateResponse(MessageVo result) {
        if (result != null) {
            final String url = result.getResult();
            mQRPicPath = mQRPicPath + StringUtil.md5(url) + ".jpg";
            File file = new File(mQRPicPath);
            if (file.exists()) {
                mQrcodeImage.setImageURI(Uri.fromFile(file));
            }
            else {
                HttpUtilProxy.i().downloadFile(url, mQRPicPath, new RequestCallBack<File>()
                {
                    
                    @Override
                    public void onSuccess(File paramT) {
                        mQrcodeImage.setImageURI(Uri.fromFile(paramT));
                    }
                });
            }
            
        }
    }
    
    public class PropagandaAdapter extends BaseAdapter
    {
        private LayoutInflater inflater;
        
        @Override
        public int getCount() {
            return mAppInfoVos.size();
        }
        
        @Override
        public Object getItem(int position) {
            return mAppInfoVos.get(position);
        }
        
        @Override
        public long getItemId(int position) {
            return position;
        }
        
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (null == convertView) {
                if (null == inflater) {
                    inflater = LayoutInflater.from(parent.getContext());
                }
                convertView = inflater.inflate(R.layout.propaganda_list_layout, parent, false);
                ViewHolder holder = new ViewHolder();
                holder.tvPlatfromName = (TextView) convertView.findViewById(R.id.propaganda_share_to_list_tv_platform_name);
                holder.imgIcon = (ImageView) convertView.findViewById(R.id.propaganda_share_to_list_img_platform_icon);
                
                convertView.setTag(holder);
            }
            AppInfoVo appInfoVo = mAppInfoVos.get(position);
            ViewHolder holder = (ViewHolder) convertView.getTag();
            holder.tvPlatfromName.setText(appInfoVo.getAppName());
            holder.imgIcon.setImageDrawable(appInfoVo.getIcon());
            return convertView;
        }
        
        class ViewHolder
        {
            TextView tvPlatfromName;
            ImageView imgIcon;
        }
    }
    
    public List<AppInfoVo> getShareApps(Context context) {
        PackageManager packageManager = context.getPackageManager();
        List<AppInfoVo> appInfoVos = new ArrayList<AppInfoVo>();
        List<ResolveInfo> resolveInfos = new ArrayList<ResolveInfo>();
        Intent intent = new Intent(Intent.ACTION_SEND, null);
        //intent.setType("text/plain");
        intent.setType("*/*");
        PackageManager pManager = context.getPackageManager();
        resolveInfos = pManager.queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
        for (int i = 0; i < resolveInfos.size(); i++) {
            AppInfoVo appInfoVo = new AppInfoVo();
            ResolveInfo resolveInfo = resolveInfos.get(i);
            appInfoVo.setAppName(resolveInfo.loadLabel(packageManager).toString());
            appInfoVo.setIcon(resolveInfo.loadIcon(packageManager));
            appInfoVo.setPackageName(resolveInfo.activityInfo.packageName);
            appInfoVo.setLauncherName(resolveInfo.activityInfo.name);
            appInfoVos.add(appInfoVo);
        }
        return appInfoVos;
    }
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:text="文字提示,请让打印店进入这个网址,打印网页即可,网址是"
        android:textSize="18sp" />

    <Button
        android:id="@+id/net_address"
        style="@style/app_common_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:onClick="toUrl"
        android:text=" http://www.3km.in/qr/"
        android:textSize="18sp" />

    <ImageView
        android:id="@+id/qrcode"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_gravity="center"
        android:src="@drawable/app_default_bitmap" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="转发到:"
        android:textSize="18sp" />

    <GridView
        android:id="@+id/propaganda_gv_share_to"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:numColumns="4" >
    </GridView>

</LinearLayout>


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值