Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

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

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

CesarHernandez

[GLOBAL: userInfoPane.html]
CesarHernandez
  • Enthusiast

  • 80 posts
  • Corona SDK

I think I found the answer to via stack overflow

 

http://stackoverflow.com/a/40201333

 

 

To be clear right now this plugin does pretty much everything. You use the raw File api on Java to write and read anywhere you want unfortunately there are certain places the app cannot read or write with out rooting the android phone. To be clear I am not an android expert, I use an iPhone 7 as my main phone and I am not to familiar with the limitation of android. I have been trying to write files to sd card for a while with java but android does not like it. I am still looking into writing in app folder on sd card but it may not be the solution you are looking for. I wish there was something I could due but I am limited the walls of phone os. I did all my testing on a KitKat device. I will try to find a solution on my 5.1 device but I am not hopeful. If anyone has any solution feel free to share.

 

To reiterate when I made this plugin I was making it to access all data inside Environment.getExternalStorageDirectory() but android considers this to be the phones internal memory which is odd to me.  

 

Dear Scott,

 

Great job dear. I know it is not as easy as appear.

 

That's ought to be the reason. I have been reading about android limitation to certain folders.

 

Really, for me will be enough to write to the app's folder at the sd. I mean, you mentioned the following: "I am still looking into writing in app folder on sd card but it may not be the solution you are looking for"...

 

This solution can be fine dear. I only need to write to a folder where the user later can take the files and the app can read the files. The idea is that SD can works as a backup, so, if the user change the phone, he has the backup file in the app folder at the sd card.

 

​I have tried with the proper name of the app to create the folder but I can't do it.

 

Have you tested creating a folder for the app (package name) at sd and works? Can you share the code to do it through your plugging?

 

For example, the app with package name com.example.foo can now freely access Android/data/com.example.foo/ on external storage devices with no permissions

 

Any chance to obtain the route to create the app data folder ? in the above example "Android/data/com.example.foo/ ?

 

Will works Context.getExternalFilesDirs()

 

Can pass this variable through your plugging ?

 

I know it is terrible different from one android version to other, according to the docs you sent dear.

 

http://stackoverflow.com/questions/40068984/universal-way-to-write-to-external-sd-card-on-android/40201333#40201333

 

Any chance will be very very appreciate dear.

 

All in all thanks so much for your excellent plugging. Great job dear.

 

Your,



[TOPIC: post.html]
#52

Scott Harrison

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

  • 1,780 posts
  • Enterprise

I added 

 

externalStorage.getExternalFilesDir()

 

https://scotth.tech/plugin-externalStorage



[TOPIC: post.html]
#53

CesarHernandez

[GLOBAL: userInfoPane.html]
CesarHernandez
  • Enthusiast

  • 80 posts
  • Corona SDK

Dear Scott, perfect. Tganks so much.

Dear, im'turning crazy to get a file passed to Android (intent). I have configured the intents to autolanch my app with certain file extension, and i have the path. But appear to be an stream. Can i use your plug ( External storage) to get this fike? I've seen a tutorial to do it for ios, but not for Android. Can you help me or guide a little?

Thanks so much again

[TOPIC: post.html]
#54

Scott Harrison

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

  • 1,780 posts
  • Enterprise

Dear Scott, perfect. Tganks so much.

Dear, im'turning crazy to get a file passed to Android (intent). I have configured the intents to autolanch my app with certain file extension, and i have the path. But appear to be an stream. Can i use your plug ( External storage) to get this fike? I've seen a tutorial to do it for ios, but not for Android. Can you help me or guide a little?

Thanks so much again

This plugin was not specifically designed for that purpose. If it works, that's great please feel free to share.



[TOPIC: post.html]
#55

totola

[GLOBAL: userInfoPane.html]
totola
  • Observer

  • 15 posts
  • Corona SDK

Dear Scott,

I would like list the files of "myFolder"

print( json.encode( externalStorage.listFiles("/myFolder",true)))

I get "java.lang.NullPointerException" is my syntax good?

/myFolder

    file1.txt

    file2.txt

    ... fileN.txt

 

but when i use print(externalStorage.doesFileExist("/myFolder/file1.txt")) i get true... I am confused

 

when i use print( json.encode( externalStorage.listFiles()))

I get no error and the list of all folders and files.

 

 

 

thanks



[TOPIC: post.html]
#56

Scott Harrison

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

  • 1,780 posts
  • Enterprise

try 

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

 

the true looks at the root of the phone. Ie phone os and sd card

 

If you want to look at the phone's storage where all the phone personal files are kept remove the true.

 

you may also want to use this api

externalStorage.doesFileExist("/myFolder")



[TOPIC: post.html]
#57

jmflores.bcn

[GLOBAL: userInfoPane.html]
jmflores.bcn
  • Observer

  • 10 posts
  • Corona SDK

Hello, Scott.
 
I just acquired the plugin and I'm doing the tests on my mobile, with Android 8.0.
After configuring build.settings like this:
 
settings =
{
plugins = ["plugin.externalStorage"] = { publisherId = "tech.scotth",  supportedPlatforms = { android = true, },  }, },
 
android =
{
usesPermissions =
{ "android.permission.WRITE_EXTERNAL_STORAGE",
   "android.permission.READ_EXTERNAL_STORAGE",
},
}
 
according to the documentation, I'm encountering some problems.
 
First of all, when I try this:
 
externalStorage.isSdCardConnected ()
 
I get a false result (but I have a micro SD card).
 
On the other hand, when I try this sentence (which also appears in this post):
 
print (json.encode (externalStorage.listFiles (externalStorage.sdCardPath (), true)))
 
I get the error: bad argument # 1 to 'listfiles' (expected string, got boolean)
 
The same thing happens to me with other externalStorage routines ...
 
Please, I will appreciate your help.
Thank you very much.
 
J. M. Flores


[TOPIC: post.html]
#58

Scott Harrison

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

  • 1,780 posts
  • Enterprise

Have you already requested real-time permission

native.showPopup( "requestAppPermission", {
   appPermission = "Storage", urgency = "Critical", listener= function ( e )
   	
   end} )


[TOPIC: post.html]
#59

jmflores.bcn

[GLOBAL: userInfoPane.html]
jmflores.bcn
  • Observer

  • 10 posts
  • Corona SDK

Hi, Scott.

 

I have forced the permission in real time just as you indicated.
During the execution, the App asked for my permission, and I granted it (is it necessary to force the permission like this for the normal execution?).
 
But, after this, if I execute the sentence:
 
native.showAlert ( "LIST", json.encode (externalStorage.listFiles (externalStorage.sdCardPath(), true)) )
 
Give an execution error indicating: LuaRuntimeException: bad argument # 1 to 'listFiles' (expected string, got function)
 
And in the case of externalStorage.isSdCardConnected(), it continues returning false.
 
I look forward to your instructions.
Thank you very much


[TOPIC: post.html]
#60

Scott Harrison

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

  • 1,780 posts
  • Enterprise

https://docs.google.com/forms/d/e/1FAIpQLSf-V3z-V3FZ5y9Sb19cxVfjx7fSRV9HIbpAGptN7DaY3Ki_DA/viewform



[TOPIC: post.html]
#61

Scott Harrison

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

  • 1,780 posts
  • Enterprise

^can you file a bug report



[TOPIC: post.html]
#62

jmflores.bcn

[GLOBAL: userInfoPane.html]
jmflores.bcn
  • Observer

  • 10 posts
  • Corona SDK

Plugin Bug Report sent. 

 

I look forward to your instructions.

Thank you very much


[TOPIC: post.html]
#63

jmflores.bcn

[GLOBAL: userInfoPane.html]
jmflores.bcn
  • Observer

  • 10 posts
  • Corona SDK

Hello, Scott.

 

Any news about this topic?

We need to implement the SD card access management shortly, so we would appreciate it if you could give us your feedback as soon as possible.

 

Thanks.

 

J. M. Flores



[TOPIC: post.html]
#64

Scott Harrison

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

  • 1,780 posts
  • Enterprise

I sorry, I usually don’t take this long but I lost my usb c to micro usb cable and have been in Disney world all week. I should be back home on Sunday.

[TOPIC: post.html]
#65

pabloapdz

[GLOBAL: userInfoPane.html]
pabloapdz
  • Contributor

  • 129 posts
  • Corona SDK

Hi Scott

 

I buyed the External Storage plugin, and I can create a new folder using :

 

 

externalStorage.makeFolder("/NewFolder", shouldLookAtRoot)

 

 

But i can't get the path of this folder (ShouldLookAtRoot) ... I can see this folder in my device, works 100%, but i need get the path ..

 

 

how can I get the path ?

 

 

Ps: I tryng

 

 

externalStorage.getExternalFilesDir(type)

 

and

 

externalStorage.getExternalFilesDir(shouldLookAtRoot)

 

and

 

externalStorage.getExternalFilesDir("NewFolder)

 

 

But this is catching a different path, not the "root" path where the "NewFolder" was created



[TOPIC: post.html]
#66

Scott Harrison

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

  • 1,780 posts
  • Enterprise

Hi Scott

I buyed the External Storage plugin, and I can create a new folder using :


externalStorage.makeFolder("/NewFolder", shouldLookAtRoot)


But i can't get the path of this folder (ShouldLookAtRoot) ... I can see this folder in my device, works 100%, but i need get the path ..


how can I get the path ?


Ps: I tryng


externalStorage.getExternalFilesDir(type)

and

externalStorage.getExternalFilesDir(shouldLookAtRoot)

and

externalStorage.getExternalFilesDir("NewFolder)


But this is catching a different path, not the "root" path where the "NewFolder" was created


Looking into this try
externalStorage.getExternalFilesDir("NewFolder”, true)

[TOPIC: post.html]
#67

pabloapdz

[GLOBAL: userInfoPane.html]
pabloapdz
  • Contributor

  • 129 posts
  • Corona SDK

Looking into this try
externalStorage.getExternalFilesDir("NewFolder”, true)

 

Not works .. 

 

This give-me the following result:

 

"/storage/emulated/0/Android/data/com.Myproject/files/NewFolder"

 

The correct answer would be:

 

"/storage/emulated/0/NewFolder"

 

I can modify this using the api of corona sdk, but I don't know if all devices have the same path "Android/data/com.Myproject/files/" to exclude, so I need the correct path :\



[TOPIC: post.html]
#68

pabloapdz

[GLOBAL: userInfoPane.html]
pabloapdz
  • Contributor

  • 129 posts
  • Corona SDK

Scott  ?



[TOPIC: post.html]
#69

Scott Harrison

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

  • 1,780 posts
  • Enterprise

Scott  ?

Sorry been busy looking at now



[TOPIC: post.html]
#70

Scott Harrison

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

  • 1,780 posts
  • Enterprise

This should be patched 


  • pabloapdz likes this

[TOPIC: post.html]
#71

pabloapdz

[GLOBAL: userInfoPane.html]
pabloapdz
  • Contributor

  • 129 posts
  • Corona SDK

This should be patched 

Can you tell me when you can fix this?



[TOPIC: post.html]
#72

dan56

[GLOBAL: userInfoPane.html]
dan56
  • Enthusiast

  • 35 posts
  • Corona SDK

I am trying to use the externalStorage plugin to copy a file the Downloads folder on Android.
 
My code is as follows:
   local pathCorona = system.pathForFile( "TESThello123.txt", system.ResourceDirectory )
   local pathOnDevice = "/Download/hello123.txt"

   local extStorageResult = externalStorage.copyFile(pathCorona, pathOnDevice)
I get the result "file saved" but I don't see the file anywhere on the phone. 
 
I also tried leaving out the Download/ from the pathOnDevice as follows: local pathOnDevice = "/hello123.txt"
but I still don't see the file anywhere on the phone. 
 
I see the build settings file mentions  -- android > 6 so I have tried the experiments above with two phones that are android 5.1 and android 7, but I don't see the file on either phone.
 
Where did the file get saved?
 


[TOPIC: post.html]
#73

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,492 posts
  • Corona SDK

How sure about this path are you?

local pathOnDevice = "/Download/hello123.txt"

That looks awfully short for a download folder on an android device.  My experience tells me that folder either doesn't exist, or if you're hoping it gets created, it won't due to permissions.

 

I may be wrong about this, but in my time looking at folder hiearchies on Android they are all deep, they often  vary and permissions are an issue. 

 

Q: Isn't there a plugin on the marketplace that lets you request the path for downloads/etc on the device your user is using?  I thought there was.



[TOPIC: post.html]
#74

pabloapdz

[GLOBAL: userInfoPane.html]
pabloapdz
  • Contributor

  • 129 posts
  • Corona SDK

As I've been following the topic to always see if it has been fixed the command to get the right path to

"externalStorage.makeFolder (" / NewFolder, shouldLookAtRoot) "

I can state what Scott said, his path to the download folder is missing, the same is for me, I need to create a folder in the "general folder" of the android and get her way, which I still can not ..
 

To copy items to the Download folder you can use the ssk plugin, but unfortunately for me it does not solve this problem =/



[TOPIC: post.html]
#75

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,492 posts
  • Corona SDK

Hi again.
 
I don't own this plugin so I have to guess a little, but the plugin docs show this function is used to get a path right?
 
local path = externalStorage.getExternalFilesDir( type )
print("Path: ", path )
I'm not clear on what 'type' should be.  I'll leave that to you.
 
However, assuming you can get the above two lines to work and print a full path to the console, then this ssk.files.* code should do the job of copying a file from documents to the path (from above)
-- 1. Build destination path root (downloads folder or whatever)
local path = externalStorage.getExternalFilesDir( ????? ) 

-- 2. Build source path
local src = ssk.files.documents.getPath( "hello123.txt" )
print( dst ) 

-- 3. Build full destination path
local dst = path  .. "/hello123.txt" 

-- 4. Copy the file
ssk.files.util.cpFile( src, dst )


See here for more on installing and using SSK:
https://roaminggamer.github.io/RGDocs/pages/SSK2/#installing-ssk2

Edited by roaminggamer, 09 November 2018 - 11:35 AM.



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