i want to write file on external storage but it gives me error:
java.io.FileNotFoundException: /mnt/media_rw/sdcard1/Backup/Contact/18-03-2016 16:03:17.vcf: open failed: EACCES (Permission denied)
My code :
fileContact = new File("/mnt/media_rw/sdcard1/", "Backup/Contact");
if (!fileContact.exists()) {
fileContact.mkdirs();
}
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:MM:ss");
String strDate = sdf.format(c.getTime());
StoragePath = fileContact.getAbsolutePath() + "/" + strDate + ".vcf";
When i write fileContact = new File("/sdcard/", "/Backup/Contact");
then it write file in internal storage
. i want to write this file on my memory card(external sdcard)
.
I am getting all mounted/external storage list from this code - http://stackoverflow.com/a/19982338/3774906
and it gives me perfect list.
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="com.xxx.xx"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-feature android:name="android.hardware.usb.host"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:autoRemoveFromRecents="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
So how can i write this file on external storage card ?