3

I am trying to share image by using share intent in Android. That showing list of installed apps after button click. But I select any one app it's not sharing. The opening app crashed or some app told sending this content type not support

My code:

Intent share = new Intent(Intent.ACTION_SEND);
            File filepath = Environment.getExternalStorageDirectory();
            File dir = new File(filepath.getAbsolutePath() + "/");
            dir.mkdirs();
            Uri uri = Uri.parse(dir+"/img.jpg");
            share.putExtra(Intent.EXTRA_STREAM,uri);
            share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            share.setType("image/jpg"); 
            startActivity(Intent.createChooser(share, "Share Image"));

and also I am giving permission for read and write external storage.

Log Cat:

I got this error repeatedly:

07-06 12:25:11.654: E/SurfaceFlinger(113): SurfaceFlinger translucent=1 isOpaque=0 isExternalDisplayLayer=0 isExternalBlockLayer0
halfer
  • 19,824
  • 17
  • 99
  • 186
Suresh
  • 701
  • 1
  • 6
  • 20

1 Answers1

1

Try This:

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
Uri uri = Uri.fromFile(new File(getFilesDir(), "foo.jpg"));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri.toString());
startActivity(Intent.createChooser(shareIntent, "Share image using"));

http://developer.android.com/training/sharing/send.html

Chaudhary Amar
  • 836
  • 8
  • 20