问题描述
随着Android奇巧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权限被拒绝。我的应用程序需要写/解压缩一个压缩文件,也写一个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.
这怎么EACCES权限被拒绝的问题与Android版本4.4.2解决了奇巧?
How can this EACCES permission denied issue be solved with Android version 4.4.2 KITKAT ?
推荐答案
我发现的;没有必要对生根。
这里有一个例子:
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);
}
这篇关于HOWTO避免" EACCES权限被拒绝"对SD卡与奇巧4.4.2版本。从谷歌的新政策的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!