英文:
Unable to list parent directory from file path
问题
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
foldersList = new ArrayList<>();
folderpath = new ArrayList<>();
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
parseAllVideo();
getUniqueFolders();
adapter = new FolderAdapter(this, foldersList);
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
private void parseAllVideo() {
try {
String[] proj = {
MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA};
Cursor videocursor = this.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, null, null, null);
if (videocursor != null) {
if (videocursor.moveToFirst()) {
int path_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
do {
String filepath = videocursor.getString(path_index);
String folder_path = MyUtils.getParentDirPath(filepath);
File file = new File(filepath);
if (file.exists()) {
}
folderpath.add(folder_path);
} while (videocursor.moveToNext());
}
videocursor.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void getUniqueFolders() {
List<String> newList = new ArrayList<>(new HashSet<>(folderpath));
Collections.sort(newList);
for (int i = 0; i < newList.size(); i++) {
String folder_name = newList.get(i).substring(newList.get(i).lastIndexOf("/") + 1);
FolderModel folder = new FolderModel(folder_name, newList.get(i));
Log.d(TAG, "base file = " + folder);
foldersList.add(folder);
}
}
Images and screenshots have been removed from the translation.
英文:
In my code am trying to collect all video file in list and warp it inside there parent directory and display it inside recycler view
, And while displaying i get a folder name 0
i don't understand where the 0
folder comes from.
And the 0
folder list all files inside my storage, And those file are perfectly warped inside their respective folder.
> and here is a screen shot of the folder zero.
code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
foldersList = new ArrayList<>();
folderpath = new ArrayList<>();
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
parseAllVideo();
getUniqueFolders();
adapter = new FolderAdapter(this, foldersList);
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
private void parseAllVideo() {
try {
String[] proj = {
MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA};
Cursor videocursor = this.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, null, null, null);
if (videocursor != null) {
if (videocursor.moveToFirst()) {
int path_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
do {
String filepath = videocursor.getString(path_index);
String folder_path = MyUtils.getParentDirPath(filepath);
File file = new File(filepath);
if (file.exists()) {
}
folderpath.add(folder_path);
} while (videocursor.moveToNext());
}
videocursor.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void getUniqueFolders() {
List<String> newList = new ArrayList<>(new HashSet<>(folderpath));
Collections.sort(newList);
for (int i = 0; i < newList.size(); i++) {
String folder_name = newList.get(i).substring(newList.get(i).lastIndexOf("/") + 1);
FolderModel folder = new FolderModel(folder_name, newList.get(i));
Log.d(TAG, "base file = " + folder);
foldersList.add(folder);
}
}![enter image description here](https://i.stack.imgur.com/rgQrz.jpg)
Here is what am trying to archive, the file in the internal folder is displayed as thumbnail by (glide, bit...) but with my code the 0
folder contains all file in my storage,
答案1
得分: 0
根据@blackapps的评论,大多数Android设备上Environment.getExternalStorageDirectory().getAbsolutePath()
的值为/storage/emulated/0。
当我检查了我的设备存储,一切都很正常,文件存储在内部存储位置。
英文:
as per @blackapps comment Environment.getExternalStorageDirectory().getAbsolutePath() value on most Android devices is /storage/emulated/0
and when i checked my device storage and everthing was fine and the file is stored in internal storage location
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论