Is it possible to rename saved files using mediastore on Android 10?

Viewed 34

I saved the file as below

I want to change the file name but I want to know how

ContentValues values = new ContentValues();

values.put(MediaStore.MediaColumns.DISPLAY_NAME, filename + ".wav");
values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/*");
values.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_MUSIC + "/" + "dir" + "/");

Uri uri = getContentResolver().insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values);

File cacheDir = getCacheDir();
File cacheFile = new File(cacheDir, filename + ".wav");

FileInputStream fis = new FileInputStream(cacheFile);
OutputStream outputStream = getContentResolver().openOutputStream(uri);

byte[] buffer = new byte[1024];
int len;
while ((len = fis.read(buffer)) != -1) {
    outputStream.write(buffer, 0, len);
}

outputStream.close();
fis.close();

I tried referring to the article below, but without success

Do you have any way? thank you

Rename file of the Mediastore which is created by app in android 10. Working on Android API 30 but shows error in API 29

0 Answers
Related