Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android program crash and .android_secure

Tags:

android

I was working on an mp3 player android project for varsity that so far just consists of a single activity that recursively adds all mp3 files on the phones sd card.

My app just kept crashing and after a lot of debugging I noticed the reason is that it finds a hidden directory /sdcard/.android_secure and when it attempts to call listFiles() on this directory the app crashes. I got around around the problem by excluding hidden files from being processed.

My question is what exactly is going on here? I assume my app doesn't have permission to access the contents of .android_secure. Is there a more robust way of scanning through an sdcard?

I've add the related code below. Any help is appreciated.

    File storage = Environment.getExternalStorageDirectory();
    addMp3Files(storage);
}

private void addMp3Files(File rootDir) {
    for (File file : rootDir.listFiles()) {
        if (file.getName().toLowerCase().endsWith(".mp3")) {
        songs.add(file.getAbsolutePath());
        } else if (file.isDirectory() && !file.isHidden()) {
            addMp3Files(file);
        }
    }
}
like image 822
kontrarian Avatar asked Sep 04 '26 12:09

kontrarian


1 Answers

The .android_secure folder is used for the App2SD feature. Files of apps that have been moved to SD card are stored here. If you check the permission bit you can see that it's ------; i.e., your application has no read permission of this folder. That's why it crashed.
To exclude files and folders that your application cannot read, such as .android_secure, you can check them with the file.canRead() method.

like image 176
LazarusX Avatar answered Sep 07 '26 01:09

LazarusX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!