2
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "My text");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(http://onman.ir/colorfinder/sample.jpg));
sendIntent.setType("*/*");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(sendIntent, "Share using"));

This code is not able to attach image when sharing intent with Gmail, also it is giving error when sharing with Facebook that share multiple image or a video only. When I change type with sendIntent.setType("image/*") then it is opening the share window of Facebook but with blank text and image.

Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96
Charu
  • 1,055
  • 13
  • 18

5 Answers5

1

for sharing you can use this code

     Intent shareIntent = new Intent();

                   shareIntent.setAction(Intent.ACTION_SEND);
                   shareIntent.setType("image/*");
                   shareIntent.putExtra(Intent.EXTRA_TEXT,"abc");
                   shareIntent.putExtra(Intent.EXTRA_STREAM, imagebitmap);
                  startActivity(Intent.createChooser(shareIntent, "Share using"));

but if you want to do in facebook it will not working through intent you should use facebook sdk to share image and text

FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
                                   .setLink(url)
                                   .setCaption(getString(R.string.fb_share))
                                   .setDescription(getString(R.string.fb_share))
                                   .setPicture(
                                                 "https://scontent-lhr3-1.xx.fbcdn.net/hphotos-xfp1/v/t1.0-9/11899955_1616850925232395_9146772907853639083_n.jpg?oh=3dd7da7bf03edee84689d66af2024880&oe=56793D62")
                                   .build();
                     uiHelper.trackPendingDialogCall(shareDialog.present());
                     dismissProgressBar();

and in your code you are sharing image url directly first you need to get bitmap then share bitmap instead of url

vishal jangid
  • 2,967
  • 16
  • 22
  • But Facebook is one the option in share intent. – Charu Nov 24 '15 at 10:07
  • but according to Facebook you can either share image or text using intent on time so when you want to make share then you should create a custom share dialog and write different code for Facebook sharing. – vishal jangid Nov 24 '15 at 10:11
  • 1
    only for Facebook you write different code and for reaming all sharing app intent will work . – vishal jangid Nov 24 '15 at 10:12
1

private void shareImage() { Intent share = new Intent(Intent.ACTION_SEND);

// If you want to share a png image only, you can do:
// setType("image/png"); OR for jpeg: setType("image/jpeg");
share.setType("image/*");

// Make sure you put example png image named myImage.png in your
// directory
String imagePath = Environment.getExternalStorageDirectory()
        + "/myImage.png";

File imageFileToShare = new File(imagePath);

Uri uri = Uri.fromFile(imageFileToShare);
share.putExtra(Intent.EXTRA_STREAM, uri);

startActivity(Intent.createChooser(share, "Share Image!"));

Try this code

Please note that when you use the setType() method, you are enabling Android to filter what apps can share your content. For example, you are sharing a text or URL, the appropriate apps to be shown can be Facebook, Messaging or Email. If you are sharing an image, proper apps can be Instagram, Snapped or Picasa.

0
 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == UPLOADIMAGE && resultCode == RESULT_OK)
    {
        uploadImage.setVisibility(View.GONE);
        imageView.setVisibility(View.VISIBLE);

        if (data !=null)
        {
            imageUri=data.getData();
            imageView.setImageURI(imageUri);
            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };

            Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
            cursor.moveToFirst();
            columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            attachmentFile = cursor.getString(columnIndex);
            Log.e("Attachment Path:", attachmentFile);
            URI = Uri.parse("file://" + attachmentFile);
            cursor.close();

        }
        else {Toast.makeText(TutorForm.this,"Uploading image failed",Toast.LENGTH_LONG).show();}




    }
    super.onActivityResult(requestCode, resultCode, data);

OnClickListner

 Intent emailIntent=new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"+ clientEmail));
        emailIntent.putExtra(Intent.EXTRA_TEXT,body);
        emailIntent.putExtra(Intent.EXTRA_SUBJECT,"Tutor Registration from App");
        emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Uri uri = Uri.parse(imageUri.toString());
        emailIntent.putExtra(Intent.EXTRA_STREAM,URI);
        startActivity(Intent.createChooser(emailIntent,"Send Via..."));
saigopi.me
  • 14,011
  • 2
  • 83
  • 54
0
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setType("image/*");

//set your message
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, msgText); 
String imagePath = Environment.getExternalStorageDirectory() + 
File.separator + "image_name.jpg";
File imageFileToShare = new File(imagePath);
Uri uri = Uri.fromFile(imageFileToShare);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
Uri uri = Uri.fromFile(imageFileToShare);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
Bharat Vasoya
  • 351
  • 4
  • 7
  • please provide more information (explanation) about your answer. – Søren Sep 18 '17 at 09:21
  • Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation [would greatly improve](//meta.stackexchange.com/q/114762) its long-term value by showing *why* this is a good solution to the problem, and would make it more useful to future readers with other, similar questions. Please [edit] your answer to add some explanation, including the assumptions you've made. – Toby Speight Sep 18 '17 at 10:05
-1

This one work for me

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
            shareIntent.setType("image/jpeg");

            shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.share_subject));
            shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, getResources().getString(R.string.share_message));

            shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(yourimagepath);

            startActivity(Intent.createChooser(shareIntent, "Share Image"));
Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96