0

This is my code:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.sharebutton:
            shareImage();
            break;

        default:
            return super.onOptionsItemSelected(item);
    }
    return true;
}

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

     share.setType("image/*");
    String imagePath = Environment.getExternalStorageDirectory()
            + "/myImage.png";

    File imageFileToShare = new File(imagePath);

    Uri uri = Uri.fromFile(imageFileToShare);
    share.putExtra(Intent.EXTRA_STREAM, uri);
    Bitmap bmp = BitmapFactory.decodeFile(imagePath);

    startActivity(Intent.createChooser(share, "Share"));
}

I am trying to share my image but it's not sharing. I am getting no error. Can anyone tell what's the problem?

buczek
  • 2,011
  • 7
  • 29
  • 40
mansi mervana
  • 33
  • 1
  • 8

1 Answers1

0
String pathURL = "File Real Path"
Uri bmpUri = Uri.fromFile(new File(pathURL));
Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("image/*");
    shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
    startActivity(Intent.createChooser(shareIntent, "Share Image"));
comeback4you
  • 716
  • 1
  • 8
  • 24