Saving file on SD card, and reading it back?

Put your problem here if it does not fit any of the other categories.

Saving file on SD card, and reading it back?

Postby deenybird » Tue Feb 15, 2011 12:52 am

We are trying to store license information for our app in a file in the downloads folder on the sdcard. We hope this will allow the user to unlock additional content, and keep it, even after deleting the app.

The bit of code we are using is posted below. The "path" object below does properly return the downloads folder but it won't save. The error we were initally getting was there was a path seperator issue now it seems to be a "Resources don't contain package for resource number".... We do have the proper code in the manifest to allow writing.

FileOutputStream out = null;
int i=0;

File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);


try{
out = context3.openFileOutput(path+"/mysavefile.dat", Context.MODE_APPEND);

out.write(unlocks);


out.flush();
out.close();
}
catch (Exception e) {
e.printStackTrace();
}


Thanks for the help!
deenybird
Developer
Developer
 
Posts: 25
Joined: Sat Nov 29, 2008 12:35 am

Top

Re: Saving file on SD card, and reading it back?

Postby imbroken » Tue Feb 15, 2011 7:53 am

I believe openFileOutput() can only take the file name as an argument. So now path separation "/" is allowed.
imbroken
Senior Developer
Senior Developer
 
Posts: 131
Joined: Thu Jan 06, 2011 6:57 pm
Location: Germnay

Re: Saving file on SD card, and reading it back?

Postby antonykk » Tue Mar 01, 2011 4:29 am

deenybird wrote:We are trying to store license information for our app in a file in the downloads folder on the sdcard. We hope this will allow the user to unlock additional content, and keep it, even after deleting the app.

The bit of code we are using is posted below. The "path" object below does properly return the downloads folder but it won't save. The error we were initally getting was there was a path seperator issue now it seems to be a "Resources don't contain package for resource number".... We do have the proper code in the manifest to allow writing.

FileOutputStream out = null;
int i=0;

File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);


try{
out = context3.openFileOutput(path+"/mysavefile.dat", Context.MODE_APPEND);

out.write(unlocks);


out.flush();
out.close();
}
catch (Exception e) {
e.printStackTrace();
}


Thanks for the help!



Android is providing some rules for the license agreements you can visit http://android-codes-examples.blogspot.com/2011/02/android-market-license-verification.html this post for shorten story about that license
antonykk
Freshman
Freshman
 
Posts: 8
Joined: Tue Jan 04, 2011 8:24 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: MSNbot Media and 19 guests