photo share intent in android

我只是一个虾纸丫 提交于 2019-11-28 14:32:50
Vaibs_Cool

Try this

Bitmap icon = mBitmap;
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/jpeg");
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
    try {
        f.createNewFile();
        FileOutputStream fo = new FileOutputStream(f);
        fo.write(bytes.toByteArray());
    } catch (IOException e) {                       
            e.printStackTrace();
    }
    share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg"));
    startActivity(Intent.createChooser(share, "Share Image"));

Refer more links

http://android-developers.blogspot.in/2012/02/share-with-intents.html

Android Share Via Dialog

Image post into facebook wall from android sdcard

This is the solution I came up with: This function allows you to share to instagram, facebook or any other app if you know the package name. If the app is not installed it redirects to the Play Store. If you send "others" as parameters, you will display a list of apps that also support image sharing.

shareImageIntent(mActivity,"image/*", "/storage/emulated/0/Pictures/Instagram/IMG_20150120_095603.jpg", "Instagram Sharing test. #Josh","com.instagram.android"); // parameters - for facebook: "com.facebook.katana" , to display list of other apps you can share to: "others"

 public void shareImageIntent(Activity a,String type, String mediaPath, String caption, String app){
        Intent intent = mContext.getPackageManager().getLaunchIntentForPackage(app);
        if ((intent != null)||(app.equals("others"))){

            // Create the new Intent using the 'Send' action.
            Intent share = new Intent(Intent.ACTION_SEND);

            if(!app.equals("others"))
                share.setPackage(app);

            // Set the MIME type
            share.setType(type);    

            // Create the URI from the media
            File media = new File(mediaPath);
            Uri uri = Uri.fromFile(media);

            // Add the URI and the caption to the Intent.
            share.putExtra(Intent.EXTRA_STREAM, uri);
            share.putExtra(Intent.EXTRA_TEXT, caption);
            // Broadcast the Intent.
            //startActivity(Intent.createChooser(share, "Share to"));
            a.startActivity(share);
            }
        else{
            intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            //intent.setData(Uri.parse("market://details?id="+"com.instagram.android"));
            intent.setData(Uri.parse("market://details?id="+app));
            a.startActivity(intent);            
            }   
        }

You can not use Intent to post to Facebook. They have specifically blocked this. You have to either use their SDK or copy it to the clipboard and have the user paste it after the facebook interface opens. I am having this same problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!