-1

I'm having troubles sharing an image from my app to other apps.

The problem is when I share the image, it doesn't include the extension and other apps like messenger, whatsapp or gmail doesn't recognise them.

My code is:

    Intent intent = new Intent(Intent.ACTION_SEND);

    String path = "android.resource://com.xxxx.xxxxxxx/drawable/image";
    Uri screenshotUri = Uri.parse(path);

    intent.putExtra(Intent.EXTRA_TEXT, "Hello world!");
    intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
    intent.setType("image/*");

    startActivity(Intent.createChooser(intent, "Share:"));

I'm having the same problem sharing audio:

    Intent share = new Intent();
    share.setAction(Intent.ACTION_SEND);

    String sharePath = "android.resource://com.xxx.xxxxx/raw/" + sound;
    Uri uri = Uri.parse(sharePath);

    share.putExtra(Intent.EXTRA_STREAM, uri);
    share.setType("audio/mp3");

    Intent i = Intent.createChooser(share, "Share Sound File");
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    baseContext.startActivity(i);

I already checked the official documentation and still having problems: https://developer.android.com/training/sharing/send.html

Thanks for help or any hints!

Anjali
  • 1
  • 1
  • 13
  • 20
mmsergi
  • 377
  • 2
  • 3
  • 9
  • Check This out it might help - http://stackoverflow.com/questions/7661875/how-to-use-share-image-using-sharing-intent-to-share-images-in-android https://guides.codepath.com/android/Sharing-Content-with-Intents – Mukeshkumar S Sep 15 '16 at 11:28

1 Answers1

1

You have to write the image or audio file to the sdcard or ExternalStorege before sharing. The reason is other apps don't have the access to the files which are in your app's private memory. So to share the image or any other file from your app, you must make it available for other apps to read.

Nitesh
  • 3,868
  • 1
  • 20
  • 26