我想移动和重命名图像文件,这个图像文件不是我的应用程序创建的,所以我可以在范围存储中移动或重命名 android 11 中的图像文件。
这是 android api 11 的重命名方法。
但它没有用。
File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "newFolder");
if (!dir.exists()) {
dir.mkdir();
}
File file = new File(model.getPicturePath());
long mediaID = getFilePathToMediaID(new File(file.getAbsolutePath()).getAbsolutePath(), this);
Uri utiOne =ContentUris.withAppendedId(MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL),mediaID);
String path = dir.getAbsolutePath()+File.separator+model.getPictureName();
Toast.makeText(this, "" +model.getPicturePath(), Toast.LENGTH_SHORT).show();
ContentValues cv = new ContentValues();
// cv.put(MediaStore.Images.Media.BUCKET_DISPLAY_NAME,".newFolder");
// cv.put(MediaStore.Images.Media.RELATIVE_PATH,Environment.DIRECTORY_PICTURES+File.separator+".newFolder");
cv.put(MediaStore.Images.Media.DATA,path);
// cv.put(MediaStore.Images.Media._ID,model.getPictureId());
getContentResolver().update(utiOne,cv,null);