Porting app to Corona

Hi there,

This is my first post to this forum.  

I’m not really a newbie, but I haven’t used Corona SDK for about 3 years.

I am looking at porting an existing app to Corona, but I also would like to retain user data from the current app. The data persists in a simple json text file.  I created a simple test app implementing the Lua File System to list files and folders.  Then I built the app using the same com.xxx.yyy package identifier.  The app updated and started correctly. However, no files or folders were listed.  The desktop app works fine.

Is it possible to access files from a specific package that has been updated to use Corona?  If this is not possible, what would you suggest as the simplest solution?

If you are published you will need to use the same keystore as you originally used.  

Devices are case-sensitive whereas Windows is not so maybe that is a cause?

Hi,

I just realised that this post is in the wrong thread/topic.  Sorry about that, but I’m new to this forum.  Is it possible to move it to somewhere more appropriate?

If you are published you will need to use the same keystore as you originally used.  

Yes, sure. I am using the same keystore as my current app and the package identifier is identical.  The app updates fine, but I can’t seem to access the user data file of the previous app.

Is there a way to access the previous app’s user data file?  What are my options?

There are far too many variables in this situation to be definitive but here’s what CoronaSDK does and perhaps you can map that to your app …

A Lua statement like this:

local filePath = system.pathForFile( "data.txt", system.DocumentsDirectory )

will result in the file being located at this path on the Android device (obviously the package name will vary):

/data/data/com.coronalabs.test.FileDemo/app\_data/data.txt

Note that this is not the same as the location returned by android.content.Context.getFilesDir() as might be used in a native Android app (if that’s what your old app is using) which would be something like:

/data/data/com.coronalabs.test.FileDemo/files/data.txt

Once you know the full path of the file in old app, you should be able to access it in the CoronaSDK app using code like this:

local packageName = system.getInfo( "androidAppPackageName") or "PACKAGE\_NAME" local testfileName = "/data/data/"..packageName.."/files/data.txt" local testfile = io.open( testfileName, "r" ) if testfile then     -- read all contents of file into a string     local contents = testfile:read( "\*a" )     print( "Contents of " .. testfileName )     print( contents )     io.close( testfile ) else     print( "ERROR: cannot open ", testfileName) end

But as I mentioned at the start, there are many variables here (behavior might vary between different versions of Android for instance) so we can’t support code like this.  Good luck!

Actually, someone pointed out that using relative paths might work better on more devices (though they might not work at all).  You’ll need to experiment.

Here’s an amended version of the code:

local testfileName = system.pathForFile( "../files/data.txt", system.DocumentsDirectory ) local testfile = io.open( testfileName, "r" ) if testfile then     -- read all contents of file into a string     local contents = testfile:read( "\*a" )     print( "Contents of " .. testfileName )     print( contents )     io.close( testfile ) else     print( "ERROR: cannot open ", testfileName) end

Many thanks for the replies.  I really appreciate it a lot.

Hi All,

I think we will use firebase or some other service as an intermediary solution to our local user data issue.  /

  1. We will update our current games to use firebase and do a release

  2. At some point in the future we will then switch our codebase to Corona. 

If you have any better ideas, I would love to hear them. 

Cheers 

If you are published you will need to use the same keystore as you originally used.  

Devices are case-sensitive whereas Windows is not so maybe that is a cause?

Hi,

I just realised that this post is in the wrong thread/topic.  Sorry about that, but I’m new to this forum.  Is it possible to move it to somewhere more appropriate?

If you are published you will need to use the same keystore as you originally used.  

Yes, sure. I am using the same keystore as my current app and the package identifier is identical.  The app updates fine, but I can’t seem to access the user data file of the previous app.

Is there a way to access the previous app’s user data file?  What are my options?

There are far too many variables in this situation to be definitive but here’s what CoronaSDK does and perhaps you can map that to your app …

A Lua statement like this:

local filePath = system.pathForFile( "data.txt", system.DocumentsDirectory )

will result in the file being located at this path on the Android device (obviously the package name will vary):

/data/data/com.coronalabs.test.FileDemo/app\_data/data.txt

Note that this is not the same as the location returned by android.content.Context.getFilesDir() as might be used in a native Android app (if that’s what your old app is using) which would be something like:

/data/data/com.coronalabs.test.FileDemo/files/data.txt

Once you know the full path of the file in old app, you should be able to access it in the CoronaSDK app using code like this:

local packageName = system.getInfo( "androidAppPackageName") or "PACKAGE\_NAME" local testfileName = "/data/data/"..packageName.."/files/data.txt" local testfile = io.open( testfileName, "r" ) if testfile then     -- read all contents of file into a string     local contents = testfile:read( "\*a" )     print( "Contents of " .. testfileName )     print( contents )     io.close( testfile ) else     print( "ERROR: cannot open ", testfileName) end

But as I mentioned at the start, there are many variables here (behavior might vary between different versions of Android for instance) so we can’t support code like this.  Good luck!

Actually, someone pointed out that using relative paths might work better on more devices (though they might not work at all).  You’ll need to experiment.

Here’s an amended version of the code:

local testfileName = system.pathForFile( "../files/data.txt", system.DocumentsDirectory ) local testfile = io.open( testfileName, "r" ) if testfile then     -- read all contents of file into a string     local contents = testfile:read( "\*a" )     print( "Contents of " .. testfileName )     print( contents )     io.close( testfile ) else     print( "ERROR: cannot open ", testfileName) end

Many thanks for the replies.  I really appreciate it a lot.

Hi All,

I think we will use firebase or some other service as an intermediary solution to our local user data issue.  /

  1. We will update our current games to use firebase and do a release

  2. At some point in the future we will then switch our codebase to Corona. 

If you have any better ideas, I would love to hear them. 

Cheers