You can try to put the following in your manifestfile:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Question
I want to display an image using the following code:
protected void onActivityResult(int requestCode, int resultCode,
Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case SELECT_PHOTO:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(
selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Log.wtf("M3K", "Above decode");
Bitmap logoBMP = BitmapFactory.decodeFile(filePath);
Log.wtf("M3K", "Below decode");
//Display image on layout
Log.wtf("M3K", "Above display");
logo.setImageBitmap(logoBMP);
Log.wtf("M3K", "Below display");
}
}
}
The issue is on Bitmap logoBMP = BitmapFactory.decodeFile(filePath);
where on Android 4.4 (tested on my Nexus 7) it will return a file not found exception, with the reason being EACCES (Permission denied). This works perfectly on an ASUS Transformer Infinity running 4.2 and worked perfectly on my Nexus 7 running 4.3. Does anyone know what has to change for KitKat compatibility?
Note: I get the image URI through the following code:
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
Solution
You can try to put the following in your manifestfile:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />