Do we need permission to get all files that is self-created by the app after the app is reinstalled in AndroidQ?
Asked Answered
R

2

2

Use-Case:

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?

If we need permission, how to ask permission and get all that PDF files from that Downloads folder in Android-Q.

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

Note: Before android Q, we can get all the files of the external storage once the permission is enabled. But after Android SDK-28, there is completely different file-system. Due to lack of proper documentation it is difficult to do minor task.

Raskind answered 26/8, 2020 at 8:0 Comment(3)
Yes, you need to ask for the permissions.Gallicism
Usually we don't need to ask permission after SDK-28 for the self-created file. So can you please elaborate your answer.Raskind
Here self-created means whether it is created by you(the developer) or the user, not by android os or the device neither by the app itself, hope you understood my point. And now the created file is on the user device. So when someone uninstall a app that means the user didn't liked the app or the app didn't worked out for the user, remember here the reason for the uninstall could be your permissions too. So now when they reinstall the app you must ask for the permissions again.Gallicism
A
1

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

Wrong question.

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.

Amitosis answered 26/8, 2020 at 16:7 Comment(1)
If we need permission, how to ask permission and list all that PDF files from that Downloads folder in Android-Q.Raskind
S
0

Yes as far permissions go, every kind of permission given with a clear-storage is "cleared" also.

Did you check if the files are actually removed after the uninstall? My best guess is that they are if they are saved in the internal storage

Samellasameness answered 26/8, 2020 at 11:3 Comment(1)
Files are saved in the MediaStore. So, they won't be deleted.Raskind

© 2022 - 2024 — McMap. All rights reserved.