Open Gallery Intent
Intent galleryIntent = new Intent( Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
galleryIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(galleryIntent, FILE_REQUEST);
OnActivity Result
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
selected_photo = data.getData();
String[] filePath = {MediaStore.Images.Media.DATA};
Cursor c = getContentResolver().query(selected_photo, filePath,null, null, null);
c.moveToFirst();
int columnIndex = c.getColumnIndex(filePath[0]);
picturePath = c.getString(columnIndex);
c.close();
Intent i = new Intent(First.this, Second.class);
i.putExtra("pic", picturePath);
startActivity(i);
}
First Activity Log
E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: 46: open failed: ENOENT (No such file or directory)
On Next Activity, i am getting error inside this function
public Bitmap decodeBitmapFromPath(String filePath) {
Bitmap scaledBitmap = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
scaledBitmap = BitmapFactory.decodeFile(filePath, options);
options.inSampleSize = calculateInSampleSize(options, 30, 30);
options.inDither = false;
options.inPurgeable = true;
options.inInputShareable = true;
options.inJustDecodeBounds = false;
scaledBitmap = BitmapFactory.decodeFile(filePath, options);
ExifInterface exif;
try {
exif = new ExifInterface(filePath);
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION, 0);
Matrix matrix = new Matrix();
if (orientation == 6) {
matrix.postRotate(90);
} else if (orientation == 3) {
matrix.postRotate(180);
} else if (orientation == 8) {
matrix.postRotate(270);
}
scaledBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0,
scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix,
true);
eW = scaledBitmap.getWidth();
eH = scaledBitmap.getHeight();
eM = matrix;
} catch (IOException e) {
e.printStackTrace();
FirebaseCrashlytics.getInstance().recordException(e);
}
return scaledBitmap;
}
Second Activity Log
java.io.FileNotFoundException: 46: open failed: ENOENT (No such file or directory) at libcore.io.IoBridge.open(IoBridge.java:492) at java.io.FileInputStream.(FileInputStream.java:160) at java.io.FileInputStream.(FileInputStream.java:115) at android.media.ExifInterface.initForFilename(ExifInterface.java:2531) at android.media.ExifInterface.(ExifInterface.java:1500) at .SecondActivity.decodeBitmapFromPath(SecondActivity.java:889)
Now, how can i access this photo in next activity as bitmap , and apply different effects on it ?