我是Android开发的新手,我想从我的应用程序打开内部内存。但它在除三星设备之外的所有设备上都是开放的。它在摩托罗拉设备,其他手机和模拟器中也很好用。我在这里得到null
:if (scanFolder == null) {return null;}
public List<Folder> loadInBackground() {
List<Folder> folderList = new ArrayList<>();
List<Song> songList = new ArrayList<>();
// Permission Check Runtime For M and above
if (PermissionChecker.checkCallingOrSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED) {
FileExtensionFilter mFileExtensionFilter = new FileExtensionFilter(Constants.fileExtensions);
if (dir != null) {
File[] scanFolder = dir.listFiles(mFileExtensionFilter);
// Getting Null over here in Samsung Device scanFolder getting null
if (scanFolder == null) {
return null;
}
// Get Folder List
for (File aScanFolder : scanFolder) {
Folder folder = new Folder();
Cursor cursor = getContext().getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Audio.Media.DATA}, MediaStore.Audio.Media.DATA + " like ? ", new String[]{"%" + aScanFolder.getAbsolutePath() + "%"}, null);
if (cursor != null) {
int count = cursor.getCount();
if (count != 0) {
if (!aScanFolder.isDirectory()) {
String path = aScanFolder.getAbsolutePath();
Song song = Helper.getSongData(Extras.getInstance().getSongSortOrder(), getContext(), path);
songList.add(song);
}
if (!aScanFolder.getAbsolutePath().startsWith("/d")) {
Log.e("FolderLoader", "Path --> " + aScanFolder.getAbsolutePath());
folder.setFile(aScanFolder);
folder.setFileCount(count);
folder.setSongList(songList);
folderList.add(folder);
}
}
}
if (cursor != null) {
cursor.close();
}
}
Collections.sort(folderList, new Comparator<Folder>() {
@Override
public int compare(Folder f1, Folder f2) {
if ((f1.getFile().isDirectory() && f2.getFile().isDirectory()))
return f1.getFile().getName().compareToIgnoreCase(f2.getFile().getName());
else if (f1.getFile().isDirectory() && !f2.getFile().isDirectory())
return -1;
else if (!f1.getFile().isDirectory() && f2.getFile().isDirectory())
return 1;
else if (!f1.getFile().isDirectory() && !f2.getFile().isDirectory())
return f1.getFile().getName().compareToIgnoreCase(f2.getFile().getName());
else return 0;
}
});
if (!dir.getAbsolutePath().equals("/")) {
Folder folder = new Folder();
if (dir.getParentFile() != null) {
folder.setFile(dir.getParentFile());
Log.e("FolderLoader", dir.getParentFile().getAbsolutePath());
folderList.add(0, folder);
}
}
}
return folderList;
} else {
// Error Message
Log.d("Folder", "Permission not granted");
return Collections.emptyList();
}
}
我在三星设备中获得此屏幕UI。