Android: How to access folder in external storage?

Hi,

I am using an ad plugin that reads/writes to the devices external storage. Unfortunately, it is a badly written SDK that doesn’t clean up after itself. The ad plugin stores files in the following location:

sdcard/Android/data/com.my.packageName/files/al

I would like to delete the contents of that folder before each ad.load() request. How can i do that? 

I know Scott Harrison has a plugin for external storage. But i don’t want to pay to clean someone else’s mess.

Any ideas?

Thnaks

Since you have a path to the files, you should be able to use the lfs.* API’s to get a list of files at that path and then use os.remove() to remove those that you wish to remove.

Rob

Hi Rob. Thanks, but it is not a reliable solution. On Android, the path to the external storage differs between devices. On my phone it is “/sdcard”. But on other android devices it could be “sdcard0”, “sdcard1”, “emulated/0”, “sdcard/emulated”, … Too many possibilities, unfortunately. With lfs, getting the right path to the external storage is the issue. Also, using the “system.” constants only returns the sandboxed directories.

Have you taken a look at Scott’s External Storage plugin?

externalStorage.getExternalFilesDir(type)

Seems like it might do what you need.

Spend the money, save the time.

Since you have a path to the files, you should be able to use the lfs.* API’s to get a list of files at that path and then use os.remove() to remove those that you wish to remove.

Rob

Hi Rob. Thanks, but it is not a reliable solution. On Android, the path to the external storage differs between devices. On my phone it is “/sdcard”. But on other android devices it could be “sdcard0”, “sdcard1”, “emulated/0”, “sdcard/emulated”, … Too many possibilities, unfortunately. With lfs, getting the right path to the external storage is the issue. Also, using the “system.” constants only returns the sandboxed directories.

Have you taken a look at Scott’s External Storage plugin?

externalStorage.getExternalFilesDir(type)

Seems like it might do what you need.

Spend the money, save the time.