Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

External Storage
Started by Scott Harrison Jan 27 2017 10:49 AM

99 replies to this topic
[TOPIC CONTROLS]
Page 1 of 4 1 2 3 »
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

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



[TOPIC: post.html]
#2

John_M

[GLOBAL: userInfoPane.html]
John_M
  • Enthusiast

  • 97 posts
  • Corona SDK

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!!!


[TOPIC: post.html]
#3

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

please try

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


[TOPIC: post.html]
#4

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

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"]


[TOPIC: post.html]
#5

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

Please note different sd cards return different things



[TOPIC: post.html]
#6

John_M

[GLOBAL: userInfoPane.html]
John_M
  • Enthusiast

  • 97 posts
  • Corona SDK

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!


[TOPIC: post.html]
#7

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

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. 



[TOPIC: post.html]
#8

John_M

[GLOBAL: userInfoPane.html]
John_M
  • Enthusiast

  • 97 posts
  • Corona SDK

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!!



[TOPIC: post.html]
#9

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

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. 



[TOPIC: post.html]
#10

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,110 posts
  • Corona SDK

@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!



[TOPIC: post.html]
#11

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

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.


  • John_M likes this

[TOPIC: post.html]
#12

John_M

[GLOBAL: userInfoPane.html]
John_M
  • Enthusiast

  • 97 posts
  • Corona SDK

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

 

Thanks again



[TOPIC: post.html]
#13

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

It should already be available.

[TOPIC: post.html]
#14

John_M

[GLOBAL: userInfoPane.html]
John_M
  • Enthusiast

  • 97 posts
  • Corona SDK

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



[TOPIC: post.html]
#15

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

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



[TOPIC: post.html]
#16

John_M

[GLOBAL: userInfoPane.html]
John_M
  • Enthusiast

  • 97 posts
  • Corona SDK

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



[TOPIC: post.html]
#17

John_M

[GLOBAL: userInfoPane.html]
John_M
  • Enthusiast

  • 97 posts
  • Corona SDK

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



[TOPIC: post.html]
#18

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

yes

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

should work



[TOPIC: post.html]
#19

John_M

[GLOBAL: userInfoPane.html]
John_M
  • Enthusiast

  • 97 posts
  • Corona SDK

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



[TOPIC: post.html]
#20

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

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



[TOPIC: post.html]
#21

John_M

[GLOBAL: userInfoPane.html]
John_M
  • Enthusiast

  • 97 posts
  • Corona SDK

Thanks for the clarification. I appreciate it.

[TOPIC: post.html]
#22

John_M

[GLOBAL: userInfoPane.html]
John_M
  • Enthusiast

  • 97 posts
  • Corona SDK

Hi Scott,

I studied your post carefully, is my following understanding correct?

externalStorage.listFiles() - gives you a list of files on the device itself (has nothing to do with an SD card)

externalStorage.listFiles(externalStorage.music) - gives you a list of files that are in the device’s /Music folder (has nothing to do with an SD card)

externalStorage.listFiles(externalStorage.sdCardPath()) - gives you a list of files and folders that are in the root folder (starting folder) of the SD card

externalStorage.listFiles(externalStorage.sdCardPath()..externalStorage.music) - gives you a list of files in the /Music folder of the SD card (if a ‘Music’ folder exists on the SD card)

Thanks

[TOPIC: post.html]
#23

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

Yes

[TOPIC: post.html]
#24

John_M

[GLOBAL: userInfoPane.html]
John_M
  • Enthusiast

  • 97 posts
  • Corona SDK

Great, thanks.

[TOPIC: post.html]
#25

John_M

[GLOBAL: userInfoPane.html]
John_M
  • Enthusiast

  • 97 posts
  • Corona SDK

Hi, I'm still trying to get this to work for an app..  I'm finding that these 2 function calls give the exact same output (a list of files on the device):

 

externalStorage.listFiles()

externalStorage.listFiles(externalStorage.sdCardPath())

 

even though that's what we have outlined in the post above.dated 06 March 2017 - 12:32 PM

 

Is that a bug, or does externalStorage.sdCardPath() have to be used differently? How do we get a list of files that are on the SD card?  print(externalStorage.isSdCardConnected()) is coming back as true

 

Also is externalStorage.sdCardPath() supposed to return a string?  I'm getting the following error when I run :print(json.encode(externalStorage.listFiles(externalStorage.sdCardPath()..'/Music'))) 

 
ERROR: Runtime error
?:0: attempt to concatenate a function value
stack traceback:
     ?: in main chunk

 

Let me know if I'm doing something wrong.

 

Thanks again




[topic_controls]
Page 1 of 4 1 2 3 »
 
[/topic_controls]