我有一個函數試圖從圖像路徑獲取圖像,它的工作原理取決於圖像。Android錯誤意圖根據路徑從圖庫中挑選圖像
出於某種原因,它工作正常,從這個位置
/storage/extSdCard/DCIM/100MEDIA/IMAG0082.jpg
但是這些位置不工作
/storage/extSdCard/DCIM/Camera/20150315_133312.jpg
/storage/emulated/0/Pictures/20150825_161105.jpg
它導致一個空白縮略圖和一個錯誤,當我嘗試上傳來自文件路徑的圖像。
這裏是我挑選的照片意圖:
//Camera Application for existing Photo
public void btnExistingPhotoClicked(View v) {
//invoke the intent to get an image from the phone
Intent pickPhoto = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickPhoto, 1);//one can be replaced with any action code
}
在此可以把它撿起實際onActivityResult,把它放在一個縮略圖,然後在一個TextView
case 1:
if(resultCode == RESULT_OK){
//function for a selected image
Uri selectedImage = imageReturnedIntent.getData();
mImageView.setImageURI(selectedImage);
Toast.makeText(this, mImageView.toString(), Toast.LENGTH_LONG).show();
Log.d("MainActivity", mImageView.toString());
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(
selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imgurl = cursor.getString(columnIndex);
cursor.close();
//The imageview is set, this is the small preview in the app
TextView tximgurl = (TextView) findViewById(R.id.txtImgUrl);
tximgurl.setText(imgurl);
Log.d("MainActivity", imgurl.toString());
//Toast.makeText(this, imgurl, Toast.LENGTH_LONG).show();
}
break;
也許你需要不同的權限來訪問這些新文件夾? – acostela
我
<使用特徵 機器人:名字= 「android.hardware.camera」 機器人:要求= 「真」/><! - - 請告訴我需要使用相機!>
<用途-permission android:name =「android.permission.read_external_storages」/>
<使用權限android:name =「android.permission.WRITE_EXTERNAL_STORAGE」/>
<使用權限android:name =「android.permission.INTERNET 「/>
–
是內部存儲器還是外部模擬路徑? – acostela