我正在尝试这一整天,但在给出了WRITE_EXTERNAL STORAGE PERMISSION之后我仍然得到了这个PERMISSION DENIED错误。 现在我在手机上尝试了这个程序。在logcat上,同样的PERMISSION ERROR也是如此。 我尝试了这个网站提供的许多代码。它总是失败。请给我一些副本数据库到sdcard的课程
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "data/com.sri.tut/databases/image_storage.db";
String backupDBPath = "image_storage.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Exception e) {
}
这是我的Logcat输出。
09-14 08:36:07.663: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:09.413: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:09.963: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:10.203: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:10.654: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:10.854: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:11.083: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:11.283: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:11.683: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:11.934: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:12.224: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:12.463: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:12.734: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:13.053: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:13.413: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:13.694: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:13.914: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:14.303: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:14.563: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:36:14.804: ERROR/Movedb(12336): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:37:42.253: WARN/PackageManager(67): Mounting container com.sri.copydata-1
09-14 08:37:45.634: WARN/InputManagerService(67): Got RemoteException sending setActive(false) notification to pid 12336 uid 10053
09-14 08:37:52.463: WARN/PackageManager(67): Code path for pkg : com.sri.copydata changing from /mnt/asec/com.sri.copydata-2/pkg.apk to /mnt/asec/com.sri.copydata-1/pkg.apk
09-14 08:37:52.463: WARN/PackageManager(67): Resource path for pkg : com.sri.copydata changing from /mnt/asec/com.sri.copydata-2/pkg.apk to /mnt/asec/com.sri.copydata-1/pkg.apk
09-14 08:38:00.773: WARN/RecognitionManagerService(67): no available voice recognition services found
09-14 08:42:05.613: WARN/PackageManager(67): Mounting container com.sri.copydata-2
09-14 08:42:11.294: WARN/InputManagerService(67): Got RemoteException sending setActive(false) notification to pid 13273 uid 10053
09-14 08:42:20.063: WARN/PackageManager(67): Code path for pkg : com.sri.copydata changing from /mnt/asec/com.sri.copydata-1/pkg.apk to /mnt/asec/com.sri.copydata-2/pkg.apk
09-14 08:42:20.063: WARN/PackageManager(67): Resource path for pkg : com.sri.copydata changing from /mnt/asec/com.sri.copydata-1/pkg.apk to /mnt/asec/com.sri.copydata-2/pkg.ap
09-14 08:42:29.033: WARN/RecognitionManagerService(67): no available voice recognition services found
09-14 08:42:51.374: ERROR/Movedb(14575): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
09-14 08:43:14.043: ERROR/Movedb(14575): Error in Copyingjava.io.FileNotFoundException: /data/data/com.sri.assign/databases/AssignmentsDB (Permission denied)
答案 0 :(得分:1)
如果您将设备连接到电脑并启用
copy files to/from computer etc...
您无权在SD卡上书写。
断开与PC的连接,然后重试或禁用复制。
答案 1 :(得分:0)
日志表示您无权从/data/data/com.sri.tut/databases/image_storage.db读取数据,默认情况下,此/ data目录是Linux系统目录,其用户和组所有者是'系统',而不是您的应用程序,因此您没有权限。
您可以在adb shell中看到详细信息,您将看到如下属性:
drwxrwx--x system system 2012-09-14 08:30 data