java - permission denied write with USB pen drive -
this 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 m trying copy apps's database usb pendrive, last time using sd card, working fine, after have change sd card path /mnt/sda/sda2
error permission denied, /mnt/sda/sda2
usb pendrive path
this copy file function copy database pendrive
private void copyfile(string inputpath, string inputfile, string outputpath) { inputstream in = null; outputstream out = null; try { //create output directory if 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 output file (you have copied 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 how call copyfile function
copyfile("/data/data/com.example.abc2/databases/","db_busdata","/mnt/sda/sda2/");
last time copied sd card , code
copyfile("/data/data/com.example.abc2/databases/","db_busdata","/mnt/sdcard/");
copied sd card working, usb pendrive errror :-
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 need mount usb drive? can mount in programmatically ? how? please give me example?
in android os, usb pendrive know sd card,
but, permission in androidmanifest.xml
need declare different permission, usb external storage need media enable permission below :-
<uses-permission android:name="android.permission.write_media_storage" />
Comments
Post a Comment