在AndroidQ中重新安装该应用程序后,我们是否需要权限才能获取该应用程序自行创建的所有文件? [英] Do we need permission to get all files that is self-created by the app after the app is reinstalled in AndroidQ?

查看:106
本文介绍了在AndroidQ中重新安装该应用程序后,我们是否需要权限才能获取该应用程序自行创建的所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用例:

在这里,我可以使用MediaStore创建并将文件保存在本地存储中,并从MediaStore获取所有文件。但是,一旦我清除存储或重新安装该应用程序,该文件将不再可用,而该文件是由同一应用程序自行创建的。重新安装应用程序后,我们是否需要权限才能读取自己创建的文件?

Here, I can create and save files in local storage using MediaStore and get all the files from MediaStore. But Once I clear-storage or reinstall the app, the files will no longer be available which was self-created by that same app. Do we need permission to read the self-created files once the app is reinstalled?

如果需要权限,如何申请权限并从该下载文件夹中获取所有PDF文件

public static ArrayList<FileModel> getExternalPDFFileList(Context context) {
    ArrayList<FileModel> uriList = new ArrayList<>();
    try {
        ContentResolver cr = context.getContentResolver();

        String[] projection = {MediaStore.Files.FileColumns._ID, MediaStore.Files.FileColumns.DISPLAY_NAME};
        String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
                + MediaStore.Files.FileColumns.MEDIA_TYPE;
        String[] selectionArgs = null;
        String selectionMimeType = MediaStore.Files.FileColumns.MIME_TYPE + "=?";
        String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension("pdf");
        String[] selectionArgsPdf = new String[]{mimeType};

        String sortOrder = android.provider.MediaStore.Files.FileColumns.DATE_TAKEN + " DESC";
        Cursor cursor = cr.query(extUri, projection, selectionMimeType, selectionArgsPdf, sortOrder + " DESC");

        assert cursor != null;
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            int columnIndex = cursor.getColumnIndex(projection[0]);
            long fileId = cursor.getLong(columnIndex);
            Uri fileUri = Uri.parse(extUri.toString() + "/" + fileId);
            String displayName = cursor.getString(cursor.getColumnIndex(projection[1]));
            uriList.add(new FileModel(displayName, fileUri));
        }
        cursor.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return uriList;
}

注意:在android Q之前,我们可以一次获取外部存储的所有文件权限已启用。但是在Android SDK-28之后,存在完全不同的文件系统。由于缺少适当的文档,很难完成次要任务。

推荐答案



重新安装应用程序后,我们是否需要权限才能读取自己创建的文件?

Do we need permission to read the self-created files once the app is reinstalled?


错误的问题。

如果您卸载应用程序然后重新安装,它将被视为其他应用程序。

If you deinstall your app and then reinstall it it is considered a different app.

因此,您的应用程序无法看到媒体存储中由卸载的应用程序创建的文件。

Hence your app cannot 'see' the files in the media store that were created by the deinstalled app.

由于没有权限,您什么也不能做。

As there are no permissions you can do nothing.

这篇关于在AndroidQ中重新安装该应用程序后,我们是否需要权限才能获取该应用程序自行创建的所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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