列出Android设备中的所有pdf文件 [英] List all pdf files in Android Devices

查看:97
本文介绍了列出Android设备中的所有pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ListView列出存储在Android设备的内部和外部存储器中的所有PDF文件.但是,我现在不知道,我能想到的唯一方法是检查文件扩展名.所以,请您给我一个提示或建议?非常感谢您的帮助.

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 file extension. So would you please give me a hint or suggestion? I really appreciate your help.

推荐答案

尽管该问题来自2011年,但该主题仍然具有相关性,此处没有适当的答案.

Even though this question is from 2011, the topic is still relevant and there's no proper answer here.

因此,以下这段代码应可在当今的Android设备上使用:

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());
}

这篇关于列出Android设备中的所有pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆