this is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.abc2"
android:versionCode="1"
android:versionName="1.1.8" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
and i m trying to copy the apps's database to USB pendrive, last time are using SD card, it is working fine, but after i have change the SD card path to /mnt/sda/sda2
it is error permission denied, /mnt/sda/sda2
is the USB pendrive path
this is the copy file function to copy the database to pendrive
private void copyFile(String inputPath, String inputFile, String outputPath) {
InputStream in = null;
OutputStream out = null;
try {
//create output directory if it doesn't exist
File dir = new File (outputPath);
if (!dir.exists())
{
dir.mkdirs();
}
in = new FileInputStream(inputPath + inputFile);
out = new FileOutputStream(outputPath + inputFile);
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
in.close();
in = null;
// write the output file (You have now copied the file)
out.flush();
out.close();
out = null;
Toast.makeText(UltilityActivity.this, "Export successful!", Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException fnfe1) {
Log.e("tag", fnfe1.getMessage());
Toast.makeText(UltilityActivity.this, "Export failed", Toast.LENGTH_SHORT).show();
}
catch (Exception e) {
Log.e("tag", e.getMessage());
Toast.makeText(UltilityActivity.this, "Export failed", Toast.LENGTH_SHORT).show();
}
}
}
this is how i call the copyfile function
copyFile("/data/data/com.example.abc2/databases/","DB_BusData","/mnt/sda/sda2/");
last time is copied to SD card , with this code
copyFile("/data/data/com.example.abc2/databases/","DB_BusData","/mnt/sdcard/");
copied to SD card are working, but USB pendrive errror with :-
03-10 10:58:13.204: D/MainActivity(1832): open failed: EACCES (Permission denied)
03-10 10:58:13.204: D/MainActivity(1832): java.io.IOException: open failed: EACCES (Permission denied)
it is need to mount USB drive? can i mount in programmatically ? how? please give me an example?