我没有从我从whatsApp 收到的uri 中获取路径。
Uri 是这样的:content://com.whatsapp.provider.media/item/66381
来自任何其他应用程序的图像在我的应用程序(如 facebook、twitter 等)中运行良好,但它不适用于 whatsapp。
任何人都可以在这里帮助我从中获取图像路径。在这种情况下,应用程序崩溃了。
我用来获取图像路径的方法:
private String getRealPathFromURI(Uri contentUri) {
String result;
String[] projection = { MediaStore.Images.Media.DATA };
CursorLoader loader = new CursorLoader(mContext, contentUri, projection, null, null, null);
Cursor cursor = loader.loadInBackground();
if(cursor == null){
result = contentUri.getPath();
}else {
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
result = cursor.getString(column_index);
cursor.close();
}
return result;
}