I want my local image file (located at res/drawable) to be converted to a Uri, so I can put it into a Intent to start an Activity.
This is what I got until now:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("image/*");
Uri uri = Uri.fromFile(new File("/res/drawable/photo.jpg"));
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.share)));
Then, the activity that receives this intent, displays the image in a ImageView. Something like this:
Uri imageUri = (Uri) getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
ImageView myImage = (ImageView) findViewById(R.id.imageView_receive);
myImage.setImageBitmap(bitmap);
But instead of displaying the image, it throws an java.io.FileNotFoundException
java.io.FileNotFoundException: No resource found for: android.resource://com.my.package/drawable/photo.jpg
I searched and tried other ways to get a Uri through my file:
Uri uri = Uri.parse("file:///res/drawable/photo.jpg");
Uri uri = Uri.parse("android.resource://com.my.package/drawable/photo.jpg");
But all of them returned the same error for me.
Why is my image not being recognized?