I am trying to list all PDF files which are stored in internal and external memory of Android device using ListView. However,I have no idea now, and the only way I can think of is checking fil开发者_开发技巧e extension. So would you please give me a hint or suggestion? I really appreciate your help.
Even though this question is from 2011, the topic is still relevant and there's no proper answer here.
So this code below should work on today's Android devices:
String selection = "_data LIKE '%.pdf'"
try (Cursor cursor = getApplicationContext().getContentResolver().query(MediaStore.Files.getContentUri("external"), null, selection, null, "_id DESC")) {
if (cursor== null || cursor.getCount() <= 0 || !cursor.moveToFirst()) {
// this means error, or simply no results found
return;
}
do {
// your logic goes here
} while (cursor.moveToNext());
}
This might be what you are looking for: MediaStore.Files
Media provider table containing an index of all files in the media storage, including non-media files. This should be used by applications that work with non-media file types (text, HTML, PDF, etc) as well as applications that need to work with multiple media file types in a single query.
精彩评论