0

I need to create two apps, one which allows you select a image file from the device and send it using an intent. My code for this is:

Intent shareIntent = new Intent(Intent.ACTION_SEND);
                shareIntent.setType("image/jpg");
                shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
                shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                startActivity(Intent.createChooser(shareIntent, "Share image using"));

This code appears to be working because if I use gmail as my desitination it seems to work fine.

My problems seem to be in the Recieve app I cannot get the image to display, Ive tried using BitmapFactory, creating drawable etc. They always come up null. I have even put the following code into my send app:

                Uri imageURI = Uri.fromFile(file);
                String string = imageURI.toString();
                string = string.replace("file://", "");
                Drawable d = Drawable.createFromPath(string);
                ImageView iv = (ImageView) findViewById(R.id.iv);
                iv.setImageDrawable(d);

which displays the image fine, but when the code is put into the recieve app d becomes null.

My recieve code currently is as follows:

  private void handleSendImage(Intent intent) throws FileNotFoundException {
        ImageView iv = (ImageView) findViewById(R.id.iv);
        Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (uri != null) {
            iv.setImageURI(uri);
        }
    }
David Gash
  • 41
  • 1
  • 4
  • Where does `file` point? If it is external storage (which it should be), does the receiving app have the manifest and runtime permissions for that? Note that `FLAG_GRANT_READ_URI_PERMISSION` only has meaning for `content` `Uri` values, not `file` ones. – CommonsWare Mar 26 '17 at 22:18
  • The file points to for example ""/storage/emulated/0/DCIM/Camera/IMG_20170326_140149.jpg"" – David Gash Mar 26 '17 at 22:23
  • That is external storage. Does the receiving app hold either `READ_EXTERNAL_STORAGE` or `WRITE_EXTERNAL_STORAGE` permissions, including handling runtime permissions on Android 6.0+? – CommonsWare Mar 26 '17 at 22:51
  • THANK YOU I was missing the runtime permission... – David Gash Mar 26 '17 at 22:57

0 Answers0