1
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.setType("image/*");

Uri uri = Uri.parse(pathToImage);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
return shareIntent;

i was used above code for sharing image on social sites.when i posting image on facebook only text is posted and image is not coming.how can we get the image and pathtoimage is string variable i am getting sever image path and stored in string variable.but it is not working.please give any solutions for my above question.?

user2853462
  • 31
  • 1
  • 5
  • possible duplicate of [Android: Share Image intent not working with Facebook?](http://stackoverflow.com/questions/12523554/android-share-image-intent-not-working-with-facebook) – vianna77 Sep 06 '15 at 19:19

3 Answers3

4

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

Community
  • 1
  • 1
Vaibs_Cool
  • 6,126
  • 5
  • 28
  • 61
  • Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg" this line indicates store image on local and u r giving temporary_file.jpg name and ur parsing image in uri.parse method.but i want directly getting image path and i want to directly post image on social sites.i am getting image path from server directly i am giving dat path to uri.parse() method.dats not working.finally my questionis i am getting image path but dat is not posting on wall? – user2853462 Oct 07 '13 at 06:44
  • check the image path and also try saving them in temp folder and replace them so that the path of folder remains the same . – Vaibs_Cool Oct 07 '13 at 06:52
  • you said first we have to save server image also on local and get the path of image and show on wall is it correct. – user2853462 Oct 07 '13 at 07:08
  • what was the data type of mBitmap. – user2853462 Nov 07 '13 at 14:05
2

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);            
            }   
        }
Josh
  • 6,251
  • 2
  • 46
  • 73
1

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.

Temsik
  • 11
  • 1