I'm trying to create folder on the SDCard on Android 2.3 device:
final File downloadFolder = new File(FILES_PATH);
if (!downloadFolder.exists()) {
Log.i(TAG, "Creating tmp directory: " + downloadFolder.mkdirs());
}
And mkdirs() returns false. FILES_PATH is the same that getExternalStorage() returns - /mnt/sdcard/.tmp/
SD card is writable from the cli with root.
Permission:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.venturezlab.tvupdater"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Why?
Try mkdir() instead of mkdirs()
Try this
final File downloadFolder = new File(Environment.getExternalStorageDirectory()+"/.tmp");
Related
I am developing a Flutter app. I am trying to add a functionality to delete a file in device storage. When i initialize a file object with the path to the file, and run file.exist() i get true. But when i run file.delete() i get
(OS Error: No such file or directory, errno = 2)when file.delete(). At the same file.exist() return true!
I have these permissions in my manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
<uses-permission android:name="android.permission.STORAGE_INTERNAL" />
and
<application
android:requestLegacyExternalStorage="true"
And i am using permission_handler to ask for permission first.
Any idea?
I am creating an app in which I would like to read a file from the sd card and then write to another file using info from the other file. When attempting to read the file I get the following error: System.UnauthorizedAccessException: Access to the path 'sdcard/android/data/App1.App1/files/' is denied.
Read Function:
private string ReadFile(string fileName)
{
var path = "sdcard/android/data/App1.App1/files/";
var filePath = Path.Combine(path.ToString(), fileName);
string text = File.ReadAllText(path.ToString());
return text;
}
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="App1.App1" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:label="Scout" android:icon="#drawable/Icon" android:theme="#style/CustomActionBarTheme"></application>
</manifest>
I have solved the issue and found that I was trying to read a folder instead of the file itself. When switching out the variable path with filePath int the read all text function the error went away.
Do not forget to add
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
into the manifest. This allows to read and write on SD card.
More details about uses-permission
It can also be a problem with your simulator and your sd card, read this topic
i have problem with writting to OTG USB.
-tablet Lenovo Yoga 8
-Android 4.4
-write to internal storage(/storage/sdcard0) and external microSD (/storage/sdcard1) working without problem
-path to USB -> /storage/usbotg
-ES File Manager writing to USB without problem
Thank you very much, and sorry my english.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xx.xxxxx.xxxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
...
MainActivity.java
File file = new File("/storage/usb0/report.pdf");
OutputStream os = new FileOutputStream(file);
document.writeTo(os);
document.close();
os.close();
i want to create new file iam using this code
try {
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "Contacts.vcf");
file.createNewFile();
} catch (IOException ioe)
{ioe.printStackTrace();}
and using this permission
<permission android:name="android.permission.MOUNT_FORMAT_FILESYSTEMS" ></permission>
but it keeps givinh me exeption that says Permission denied
you need to use this permission in manifest file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
when you write any file in External Storage(SD CARD) or Internal Storage ,You have to add permission in manifest file...
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
add this permission into your manifest file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Give WRITE_EXTERNAL_STORAGE permission to your AndroidManifest file as shown below:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
.........
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
We need to create our own file structure on sdcard for storing preference files,database files and files ?
Is this possible ? I know we can store files anywhere on sdcard but not sure about SQLiteDatabase files and Shared Preference files .
Please provide me suggestions on this.
Thanks in Advance.
Ya its possible while developing an application.in manifest just give
android:installLocation="preferExternal"
then the application and the file of the application will be dierectly written to the external storage of the device that is to the SD card.You will be having two more options "auto" and "intenalOnly" just like this
<manifest xmlns:android="*******************"
package="*************"
android:versionCode="1"
android:installLocation="auto"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>