android kitkat 4.4.2版本是针对writeaccess实现的新的Google政策,到目前为止我还不了解。
我通过其他应用程序了解到很多有关此问题的信息。他们获得“拒绝EACCES权限”。我的应用程序需要编写/解压缩zip文件,还需要写入sqlite数据库。
如何使用Android 4.4.2 KITKAT解决这个EACCES权限被拒绝的问题?
最佳答案
我在xda forum中找到了解决此问题的可行解决方案;无需生根。
这是一个例子:
/**
* 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);
}