我编写的android应用程序有问题。 她在我的平板电脑(Android 4.4)和旧手机(Android 5)上运行良好
我在Android 6上拥有一部新手机,现在,我的应用程序无法访问系统上的文件。对于我的平板电脑,我需要保持minSdkVersion = 19(对于调试,我尝试使用23值,结果是相同的)
出于调试目的,我在主要活动代码中插入:
Log.i("DEBUGLIRICNED", "USER : " + System.getProperty("user.name"));
String debug = new String();
List<String> listePath = new ArrayList<>();
listePath.add("/sdcard/Doc");
listePath.add("/sdcard/DCIM");
listePath.add("/storage/emulated/0/Doc");
listePath.add("/storage/emulated/0/DCIM");
listePath.add("/sdcard/File.txt");
listePath.add("/storage/emulated/0/File.txt");
for (String path: listePath) {
File file = new File(path);
debug = debug + "\n" + path + ": " + file.exists() + " - " + file.canRead() + " - " + file.canWrite();
debug = debug + "\n" + path + ": " + file.getAbsoluteFile().exists() + " - " + file.getAbsoluteFile().canRead() + " - " + file.getAbsoluteFile().canWrite();
if (file.isDirectory()) {
File[] files = file.listFiles();
if (files==null) {
debug = debug + "\n listFiles return null";
} else {
debug = debug + "\n listFiles return " + files.length + " elements";
}
}
}
Log.i("DEBUGLIRICNED", debug);
这给了我输出:
10-11 13:31:10.146 30128-30128/com.aned.lyricned2_mobile I/DEBUGLIRICNED: USER : root
10-11 13:31:10.152 30128-30128/com.aned.lyricned2_mobile I/DEBUGLIRICNED: /sdcard/Doc: true - false - false
/sdcard/Doc: true - false - false
listFiles return null
/sdcard/DCIM: true - false - false
/sdcard/DCIM: true - false - false
listFiles return null
/storage/emulated/0/Doc: true - false - false
/storage/emulated/0/Doc: true - false - false
listFiles return null
/storage/emulated/0/DCIM: true - false - false
/storage/emulated/0/DCIM: true - false - false
listFiles return null
/sdcard/File.txt: true - false - false
/sdcard/File.txt: true - false - false
/storage/emulated/0/File.txt: true - false - false
/storage/emulated/0/File.txt: true - false - false
因此,文件存在,但无法读取,并且用户似乎是root用户(奇怪的是,因为我尝试使用Root Checker Basic来确定用户身份,而且我不在手机上不是root用户)
如果使用JuiceSSH在/ storage / emulated / 0 /上执行“ ls -l”,则会得到输出:
drwxrwx--- root everybody 1970-01-10 01:09 Alarms
drwxrwx--- root everybody 2019-09-29 18:57 Android
drwxrwx--- root everybody 2019-10-05 17:14 DCIM
drwxrwx--- root everybody 2019-10-04 17:47 Doc
drwxrwx--- root everybody 2019-10-04 17:54 Download
-rw-rw---- root everybody 0 2019-10-11 12:57 File.txt
drwxrwx--- root everybody 1970-01-10 01:09 LGBackup
drwxrwx--- root everybody 1970-01-10 01:09 Movies
drwxrwx--- root everybody 1970-01-10 01:09 Music
drwxrwx--- root everybody 1970-01-10 01:09 Notifications
drwxrwx--- root everybody 2019-10-05 16:10 Pictures
drwxrwx--- root everybody 1970-01-10 01:09 Podcasts
drwxrwx--- root everybody 1970-01-10 01:09 Ringtones
drwxrwx--- root everybody 2019-10-08 20:31 Tmp
drwxrwx--- root everybody 2019-09-30 08:17 VoiceRecorder
drwxrwx--- root everybody 2019-10-06 16:36 com.facebook.orca
-rw-rw---- root everybody 0 2019-10-11 13:16 out.txt
drwxrwx--- root everybody 2019-10-04 18:28 romtoolbox
drwxrwx--- root everybody 2019-10-10 13:41 test
我对AndroidManifest.xml拥有此权限:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aned.lyricned2_mobile">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
...
我尝试添加READ_EXTERNAL_STORAGE权限,但没有成功
所以,我有点迷茫,为什么我的应用程序无法读取现有文件?我为什么要生根?为什么我所有的文件都具有root所有者??
谢谢!