开发者

List all pdf files in Android Devices [duplicate]

This question already has answers here: Search all .pdf files present in the Android device (5 answers) Closed 4 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜