External Storage

External Storage

View and activate on the Corona Store

This Android plugin allows you to control/manage files outside of the app sandbox (files on the device).
Documentation

Thanks for providing this great plugin!! Access to external storage was a feature desired by many developers for a real long time. 

I purchased your plugin and was able to get the example you provided on GIT (https://github.com/scottrules44/externalStorage-demo) to work well on my Android Samsung S7 Edge device which is running Android Version 6.0.1

I have a folder on the SD card named exactly /Music, so I tried this

print( json.encode( externalStorage.listFiles("/Music")))

but I get a null pointer exception. Am I using the wrong syntax? If you put a folder name that you have on your SD card does it work for you?  I must be doing something wrong.

Also I see this in the docs:

Properties

The following return strings can be used in copy, delete, get and list files with apis above

• externalStorage.dcim

• externalStorage.download

• externalStorage.movies

• externalStorage.ringtones

• externalStorage.podcasts

• externalStorage.music     

I got the example that is on GIT to work, but when I try to substitute in the externalStorage.music mentioned above I get null pointer exceptions.  

I did the following since the above says to use those properties with the apis above:

print( json.encode( externalStorage.listFiles(externalStorage.music)))

is that the wrong syntax?

Can you possibly provide a quick working example of how to get a list of music files that a user has on their SD card, and also how to use the properties listed above?

Thanks again for your great work on this plugin!!!

please try

print( "Files" ) print( "----------------" ) print( json.encode( externalStorage.listFiles(externalStorage.sdCardPath()))) print( "----------------" )

I plugin my rooter sd card gave me the following out

[".\_.Trashes","cm-14.zip",".Trashes",".Spotlight-V100","APM","DCIM","open\_gapps-arm-7.zip","LOST.DIR",".android\_secure","Android",".\_UPGRADE.bin",".dog\_watch",".srcMid",".fseventsd"]

Please note different sd cards return different things

Thanks so much for the fast reply. I appreciate it. I will try that out this weekend.  

I see properties listed in your docs as so:

 

Properties

The following return strings can be used in copy, delete, get and list files with apis above

• externalStorage.dcim

• externalStorage.download

• externalStorage.movies

• externalStorage.ringtones

• externalStorage.podcasts

• externalStorage.music    

 

What is the syntax for using those? So far nothing I tried seemed to work.  I’m hoping externalStorage.music will give me a list of paths to songs the user has on their SD card (in order to be able to play them). If not, what is the syntax for using the above properties in code?

 

Thanks again.  You make great plugins, I see you have many, I’m going to check the others out also and I recommend that anyone else reading this should too!

They are shortcuts to other files on the phone. Note external storage is what android call the phone storage. This plugin actually allows you to dig into the phone files. The externalStorage.music is a shortcut to the “/Music” directory on the phone it self. Mirco sd cards can have all kinds of crap on them. The developer using the plugin is responsible for find and sorting though the sd card. 

That sounds great. So wouldn’t this work for the shortcut?

               print( json.encode( externalStorage.listFiles(externalStorage.music)))

It gives me null pointer error though.

How would that shortcut be used with your listFiles() function?

Thank you again!!

Certain phones are really restrictive for security reasons on which paths you can access. There is nothing I can do on my side it is just the way the software works. 

@Scott, not very helpful for a paid plugin.  I was actually looking for a plugin that did just that and I was considering purchasing your plugin to be able to play music (whilst my app was running) from a users music library but if this doesn’t work that is a lost sale.  

Most devices will default /music to internal storage even if an SD card is present. My device has 128GB internal storage but no SD card slot so, in my scenario, would your plugin fail to read my /music directory?

Being non-enterprise has its limitations sometimes!

I want to apologize, it was a bug on my part. This should be fixed in an update coming tonight. You should be able to read from where every you want. I though security was the reason but I was reading to low.

Thanks Scott.  You mention a new release in the above post. Do you know when that might be published?

Thanks again

It should already be available.

Thanks Scott.  Do new releases show on the marketplace page?

https://marketplace.coronalabs.com/plugin/external-storage

it says

Last Updated
Jan 27, 2017

that’s why I wasn’t sure.

We just get access to your new version of the plugin when we do a build?  in other words, by us just doing the following, we’ll get your new version?  (I don’t know how the plugins work behind the scenes)

settings =
{
    android = {
        – android > 6
        usesPermissions = {
            “android.permission.WRITE_EXTERNAL_STORAGE”,
            “android.permission.READ_EXTERNAL_STORAGE”,
        }
    },
    plugins = {
        [“plugin.externalStorage”] =
            {
                publisherId = “tech.scotth”,
                supportedPlatforms = {
                    android = true,
                },
            },
    },
}

Thanks again for the great work

Screen%20Shot%202017-03-05%20at%208.18.5

very cool. thanks. I guess it will be integrated during the build process. thank you!

After your bug fixes, does that mean this would be the correct syntax to use your externalStorage.music property?

 print( json.encode( externalStorage.listFiles(externalStorage.music)))

or is there other syntax that should be used to use the externalStorage.music property mentioned in your docs here?

https://scotth.tech/plugin-externalStorage

Thanks again

yes

 print( json.encode( externalStorage.listFiles(externalStorage.music)))

should work

great! I’ll try it out early this week. Thank you!

I just want to clarify something really fast before I go to bed.

externalStorage.listFiles()

is access’s the devices files i.e. “myPhone”

externalStorage.listFiles(externalStorage.music) 

is access’s the devices music files i.e. “myPhone/Music”

externalStorage.listFiles(externalStorage.sdCardPath())

= “myPhone/SDCardPath”

^This should give you info about files on the sd card

if there is a folder called “Music”(<- notice the capital M) then

externalStorage.listFiles(externalStorage.sdCardPath()..externalStorage.music)

= “myPhone/SDCardPath/Music”

Hopefully this makes sense