ANR -输入调度超时- Android 11



我的应用程序只在android 11设备上出现ANR错误。输入调度超时意味着主线程陷入循环,但根据我的logcat跟踪,我所理解的是file.exists()行有问题。

这是我的logcat trace

at libcore.io.Linux.access (Native method)
at libcore.io.ForwardingOs.access (ForwardingOs.java:72)
at libcore.io.BlockGuardOs.access (BlockGuardOs.java:73)
at libcore.io.ForwardingOs.access (ForwardingOs.java:72)
at android.app.ActivityThread$AndroidOs.access (ActivityThread.java:7937)
at java.io.UnixFileSystem.checkAccess (UnixFileSystem.java:281)
at java.io.File.exists (File.java:815)
at com.****************.FileUtils.fileIsExists (FileUtils.java:17)

这里是fileulis。class

public class FileUtils {
public static boolean fileIsExists(String path) {
if (path == null || path.trim().length() <= 0) {
return false;
}
try {
File f = new File(path);
if (!f.exists()) {
return false;
}
} catch (Exception e) {
return false;
}
return true;
}
}

在Manifest中添加MANAGE_EXTERNAL_STORAGE标志。通过打开带有ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION意图的设置,提示用户允许所有文件访问。赋予权限

最新更新