简体   繁体   中英

nomedia file in cache folders (Android)

I'm trying to create a.nomedia file into cache folder with following code

private static final String NOMEDIA_FILE = ".nomedia";
    path = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Android/data/"+cnt.getApplicationInfo().packageName+"/cache/");
    path.mkdirs();

    file= new File(path,NOMEDIA_FILE);
    if (!file.exists()){
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

file.createNewFile() returns true, later file.exists() return true , but the file dont appears at the folder. If I use another path the snipplet works. Are the cache folders automatically ignored in media scan? If not, how can I make the.nomedia file in there?

Thanks

The file does exist but is hidden in default directory lists; that's what the prefixed period (.) does.

Confirm from the command line by starting an adb shell and using ls -a to show all files. It would look something like this:

C:\Users>adb shell
root@android:/ # cd /sdcard/learnpad
root@android:/sdcard/learnpad # ls -a
.nomedia
data.learnpad.co
profile.xml

The file does exist.

It is your file explorer's settings that determine if you can see a hidden folder or not.

Just open your file explorer, go to settings, and turn on "show hidden folders"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM