private void queryFiles(){
        String[] projection = new String[] { MediaStore.Files.FileColumns._ID,
            MediaStore.Files.FileColumns.DATA,
            MediaStore.Files.FileColumns.SIZE
        };
        Cursor cursor = getContentResolver().query(
            Uri.parse("content://media/external/file"),
            projection,
            MediaStore.Files.FileColumns.DATA + " like ?",
            new String[]{"%.txt"},
            null);

        if (cursor != null) {
            if (cursor.moveToFirst()) {

                int idindex = cursor
                    .getColumnIndex(MediaStore.Files.FileColumns._ID);
                int dataindex = cursor
                    .getColumnIndex(MediaStore.Files.FileColumns.DATA);
                int sizeindex = cursor
                    .getColumnIndex(MediaStore.Files.FileColumns.SIZE);
                do {
                    String id = cursor.getString(idindex);
                    String path = cursor.getString(dataindex);
                    String size = cursor.getString(sizeindex);
                    docBean.setId(id);
                    docBean.setPath(path);
                    docBean.setSize(size);
                    int dot=path.lastIndexOf("/");
                    String name=path.substring(dot+1);
                    Log.e("test",name);
                } while (cursor.moveToNext());
            }
        }
        cursor.close();
    }

 

相关文章:

  • 2021-09-10
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2021-09-08
  • 2022-12-23
  • 2021-11-18
  • 2021-09-05
相关资源
相似解决方案