Android: File name not changing programmatically

867 views Asked by At

I tried to change the file name of a song by programmatically by using the code

File from = new File(filedirectory,currentName+type);
                File to = new File(filedirectory,newName+type);
                from.renameTo(to);

But after executing the code the current file is not show in the music list, also the new one is not showing in the list.

The file path and the file name are:

filedirectory:  /storage/emulated/0/media/audio/music/
newName:  aaaa.m4a
currentName:  bbb.m4a

In the manifest I given all the necessary permission and am executing the code in Kitkat.

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />

After rename the file, I checked whether the file exists or not by pragmatically, the result is file not exists with the new name.

1

There are 1 answers

2
civic.LiLister On

Have you ever tried to use "adb shell" and "cd /storage/emulated/0/media/audio/music/", then list file and check the files there? Whether the filename has been changed or not?

If the filename changed, then it is an issue of sync in the Music Player.

I have ever met issue that I changed the photo album, but cannot get the changes in my App by get system photo album through content provider. I have no idea how to solve it, and it disappears after phone restarted.