我想獲取圖像路徑並上傳到服務器。 在這裏,我成功地從圖庫中讀取圖像並設置爲圖像視圖,但圖像路徑返回null。Android中的圖像路徑返回null
public void onActivityResult(int requestCode, int resultCode, Intent data)
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
// Get the url from data
Uri selectedImageUri = data.getData();
if (null != selectedImageUri) {
// Get the path from the Uri
String path = getRealPathFromURI(getActivity(), selectedImageUri);
Log.i(TAG, "IMAGE" + path);
Log.d("INFO", selectedImageUri.toString());
// Set the image in ImageView
profilepicture.setImageURI(selectedImageUri);
}
}
}
}
/* Get the real path from the URI */
public String getRealPathFromURI(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = {MediaStore.Images.Media.DATA};
cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
'形象Android'路徑返回null。一點都不。錯誤的主題。 getRealPathFromURI()返回null。 – greenapps
'想要獲取圖像路徑'。從何而來?你沒有告訴你從哪裏得到'形象'。或者那個意圖。 – greenapps