与额外的文本和图像共享意图

时间:2015-05-11 10:58:13

标签: android

我正在尝试与Andriod中的另一个应用程序共享信息。

我尝试过这个,但它工作得非常慢。有更好的方法吗?

       try {
            Uri imageUri = null;
            try {
                imageUri = Uri.parse(MediaStore.Images.Media.insertImage(context.getContentResolver(), 
                    bitmap, null, null));

            } catch (Exception e) {e.printStackTrace();}

            shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_TEXT, contentText);
            shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
            shareIntent.setType("*/*");

        } catch (android.content.ActivityNotFoundException ex) {
            ex.printStackTrace();
        }

        new PopUpShareDialog().new Launchables(context, dialogShare, socialGv).execute();


 class Launchables extends AsyncTask<String, String, JSONObject>{
    ProgressDialog progressDialog;
    Context context;
    List<ResolveInfo> launchables;
    Dialog dialogShare;
    ExpandableHeightGridView socialGv;

    public Launchables(Context context, Dialog dialogShare, ExpandableHeightGridView socialGv){
        this.dialogShare = dialogShare;
        this.socialGv = socialGv;
        this.context = context;
    }

    @Override
    protected void onPreExecute() { 
        progressDialog = ProgressDialog.show(context, "", "" + context.getString(R.string.popup_loaded));
    }

    @Override
    protected JSONObject doInBackground(String... params) {
        // TODO Auto-generated method stub
        launchables = context.getPackageManager().queryIntentActivities(shareIntent, 0);

        return null;
    }

    @Override
    protected void onPostExecute(JSONObject json) {
        progressDialog.dismiss();


        Log.d("", "PackageManager");    

        Collections.sort(launchables, new ResolveInfo.DisplayNameComparator(context.getPackageManager()));

        shareSocAdapter = new ShareSocialsAdapter(context.getPackageManager(), launchables, context);
        socialGv.setAdapter(shareSocAdapter);   

        socialGv.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
                ResolveInfo launchable = shareSocAdapter.getItem(position);
                ActivityInfo activity = launchable.activityInfo;
                ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
                shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                shareIntent.setComponent(name);
                context.startActivity(shareIntent);  

            }
        }); 

        dialogShare.show();

    }
}

0 个答案:

没有答案