Reputation: 53
I'm creating an excel file directly on Android. The code is working fine, I can verify the .xls has been created and I can check it's content from a rooted phone. However I want save the excel file in a different folder from the project itself (which is /data/data/mypackage/files/). I want to save it on the normal phone documents, which would be something like "/storage/sdcard0/Documents/test.xls". I get a message saying "Permission denied" when trying to save the .xls file on that folder.
How can I get access to those folders?
Here I'm creating the excel file
WriteExcel test = new WriteExcel();
test.setOutputFile("/data/data/com.example.interfaz/files/test.xls"); // here is where I want to save the file to "/storage/sdcard0/Documents/test.xls"
try {
test.write();
} catch (WriteException e) {
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
}
Upvotes: 0
Views: 653
Reputation: 1850
Check out this page for more info on saving files:
http://developer.android.com/training/basics/data-storage/files.html#GetWritePermission
Make sure you have the permission in your manifest to write files to external storage:
<manifest ...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
</manifest>
Upvotes: 0
Reputation: 14472
Did you add permissions to your manifest?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
You should also not hard code the SDCard location since it can, and does, changes between devices.
Instead, use Environment.getExternalStorageDirectory()
Upvotes: 1