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);
}
}