0
這是我的代碼,我在我的LG G3上運行這個應用程序,它的工作原理,但在屏幕上出現「圖像無效」的圖像不出現在屏幕上。ImageView在Android 5上工作,但沒有在Android 6上工作,我該如何解決?
selectedImage = null;
orientation = -1;
selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
// Get the cursor
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
Cursor cursorF = getContentResolver().query(selectedImage, new String[]{MediaStore.Images.ImageColumns.ORIENTATION}, null, null, null);
// Move to first row
cursor.moveToFirst();
if (cursorF == null || cursorF.getCount() != 1) {
orientation = 90; //Assuming it was taken portrait
} else {
cursorF.moveToFirst();
orientation = cursorF.getInt(0);
}
//Toast.makeText(this, "orientation: " + orientation, Toast.LENGTH_LONG).show();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imgDecodableString = cursor.getString(columnIndex);//imgDecodableString = percorso completo immagine
cursor.close();
bmpImage = BitmapFactory.decodeFile(imgDecodableString);
bmpImage = RotateBitmap.rotateImageIfRequiredFile(bmpImage, orientation);
ImageView imgView = (ImageView) findViewById(R.id.imgView);
// Set the Image in ImageView after decoding the String
imgView.setImageBitmap(bmpImage);
//name of image
String sFilePath = getRealPathFromURI(selectedImage);
String saPathParts[] = sFilePath.split("/");
String sFileName = saPathParts[saPathParts.length - 1];
filename = sFileName;
Toast.makeText(this, "filename:" + filename, Toast.LENGTH_LONG).show();
if (bmpImage == null) {
Toast.makeText(getBaseContext(), "Image invalid", Toast.LENGTH_SHORT).show();
}
}
這可能是原因,但我不知道如何解決?你能給我更具體的建議嗎? –
@PasqualeMoramarco看看這裏:https://developer.android.com/training/permissions/requesting.html – amitairos
我讀過這個頁面,但他們不是很有經驗,我應該更改代碼中的內存讀取權限?非常感謝你 –