账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    关于通过MediaStore获取手机内所有pdf文件的问题
    29
    0

    我这样通过下面的代码拿到了手机内的pdf文件,但是我试了一下,比如第一次进来搜索到手机内有10个pdf文件,我退出来,然后让微信朋友给我发一个pdf,我打开pdf,我确认这个pdf已经保存在手机内了,再打开搜索pdf的Activity,这时应该有11个pdf文件,但还是只有10个pdf文件,这个该怎么解决呢?在网上搜了一下,说是没有把文件添加到MediaStore里面,但是应该怎么操作呢?最好有相关代码,谢谢
    ` private void getAllPdf() {

        ContentResolver cr = getActivity().getContentResolver();
        Uri uri = MediaStore.Files.getContentUri("external");
        String[] projection = null;
        String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
                + MediaStore.Files.FileColumns.MEDIA_TYPE_NONE;
        String[] selectionArgs = null; // there is no ? in selection so null here
        String sortOrder = null; // unordered
        Cursor allNonMediaFiles = cr.query(uri, projection, selection, selectionArgs, sortOrder);
        // only pdf
        String selectionMimeType = MediaStore.Files.FileColumns.MIME_TYPE + "=?";
        String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension("pdf");
        String[] selectionArgsPdf = new String[]{mimeType};
        Cursor cursor = cr.query(uri, projection, selectionMimeType, selectionArgsPdf, sortOrder);
        while (cursor.moveToNext()) {
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            String filePath = cursor.getString(column_index);//所有pdf文件路径
            String fileName = getFileNameWithSuffix(filePath);//所有文件名称
        }
    }

    `

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    • 血月恶魔 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部