本文介绍了如何避免“EACCES 权限被拒绝"在带有 KITKAT 4.4.2 版本的 SDCARD 上.谷歌的新政策的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

android kitkat 4.4.2 版本是为 writeaccess 实施的新谷歌策略,我目前还不明白.

With the android kitkat 4.4.2 version is a new google policy implemented for writeaccess, which I do not understand so far.

我在其他应用中阅读了很多有关此问题的信息.他们得到EACCES 许可被拒绝".我的应用程序需要编写/解压缩一个 zip 文件,还需要写入一个 sqlite 数据库.

I read a lot about this issue with other apps. They get a "EACCES permission denied". My app needs to write/unzip a zipfile, also write to a sqlite-database.

Android 4.4.2 KITKAT 版本如何解决 EACCES 权限被拒绝的问题?

How can this EACCES permission denied issue be solved with Android version 4.4.2 KITKAT ?

推荐答案

我在 xda 论坛;无需生根.
这是一个例子:

I found a working solution to this issue in xda forum; there is no need for rooting.
Here's an example :

/**
 * Returns an OutputStream to write to the file. The file will be truncated immediately.
 */
public OutputStream write()
        throws IOException {
    if (file.exists() && file.isDirectory()) {
        throw new IOException("File exists and is a directory.");
    }

    // Delete any existing entry from the media database.
    // This may also delete the file (for media types), but that is irrelevant as it will be truncated momentarily in any case.
    String where = MediaStore.MediaColumns.DATA + "=?";
    String[] selectionArgs = new String[] { file.getAbsolutePath() };
    contentResolver.delete(filesUri, where, selectionArgs);

    ContentValues values = new ContentValues();
    values.put(MediaStore.Files.FileColumns.DATA, file.getAbsolutePath());
    Uri uri = contentResolver.insert(filesUri, values);

    if (uri == null) {
        // Should not occur.
        throw new IOException("Internal error.");
    }

    return contentResolver.openOutputStream(uri);
}

这篇关于如何避免“EACCES 权限被拒绝"在带有 KITKAT 4.4.2 版本的 SDCARD 上.谷歌的新政策的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 09:01