权限被拒绝的错误,同时数据库复制到SD卡特等(PERMISSION DENIED error whi

2019-09-22 08:36发布

我想这个一整天,但我给WRITE_EXTERNAL存储许可后还我仍然得到这个权限被拒绝的错误。 现在,我想这个程序我的手机。 同样,相同的权限错误是logcat的。 我在此website.It许多可用的代码试图总是fails.Guide我一些tuorials拷贝数据库到SD卡

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)

Answer 1:

如果您将设备连接到您的电脑并启用

copy files to/from computer etc...

您将无法访问在SD卡上写。

从计算机上断开连接,然后再试一次或禁止复制。



Answer 2:

日志说你没有权限来读取数据/data/data/com.sri.tut/databases/image_storage.db,默认情况下这个/ data目录是Linux系统目录下,它的用户和组的所有者是“系统”,而不是你的应用程序,让你不具有的权限。

你可以看到在亚行外壳细节,你会看到这样的特性如下: drwxrwx--x system system 2012-09-14 08:30 data



文章来源: PERMISSION DENIED error while copying database to sdcard .pl