1. Obtain the image file based on the Contact Image Uri and display it on ImageView. The Code is as follows:
Uri uri = Uri.parse("content://com.android.contacts/display_photo/1" afd = getContentResolver().openAssetFileDescriptor(uri, "r" [] buffer = [16 * 1024 FileInputStream fis = FileOutputStream fos = FileOutputStream( File("sdcard/11212" ByteArrayOutputStream temp_byte = ((size = fis.read(buffer)) != -1 fos.write(buffer, 0 temp_byte.write(buffer, 0 image.setImageBitmap(BitmapFactory.decodeByteArray(temp_byte.toByteArray(), 0 } } }
As you can see above, uri is the photo_uri field in the view_data view of the contact database. The final id should be adjusted according to the actual situation.
2. Obtain the resource storage path based on mediaURI
Cursor cur = getContentResolver().query(Uri.parse("content://media/external/images/media/279"), , , , (cur != ( i = 0; i < cur.getColumnCount(); i++ Log.d("Davds", "name = " + Log.d("Davds", "" + cur.getString(cur.getColumnIndex("_data" }
The value obtained from the filed corresponding to _ data is the file storage path.
The following figure is displayed in the database (images table in the MediaProvider database ):