Cannot select Documents from Recent in FileSelector android

Viewed 368

I am allowing user to select particular type of files (pdf,docx,xlsx) from local storage to upload it to the php server

1 ) When user select file through any installed app like FileExplorer , ESFileExplorer , then he can upload the file to the server successfully

Uri of selected file : content://media/external/file/104310

File path selected file : /storage/emulated/0/Download/Bipasha-Basu-Cover-of-Noblesse-India_August_2014_08A.pdf

2 ) When user select file through Recent from FileSelector (Android default), then he can't upload the file to the server.

Uri of selected file : content://com.android.providers.downloads.documents/document/28433

File path selected file : /data/user/0/com.android.providers.downloads/cache/enquiry_chat_1044781500443064.pdf

Error Message : java.io.FileNotFoundException: /data/user/0/com.android.providers.downloads/cache/enquiry_chat_1044781500443064.pdf (Permission denied)

My code:

public static void openDocuments(Activity activity) {
        Intent intent = new Intent();
        intent.setType("*/*");
       String[] mimetypes = {"application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/msword","application/pdf","application/docx","application/xlsx","application/pptx","application/pptx","application/txt"};
        intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
        intent.setAction(Intent.ACTION_GET_CONTENT);
        activity.startActivityForResult(Intent.createChooser(intent, "Choose a file to send..."), MediaConstants.DOCUMENT_REQUEST);
    }

AndroidManifest.xml

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="${applicationId}.provider"
        android:exported="false"
        android:readPermission="com.android.providers.READ_DATABASE"
        android:writePermission="com.android.providers.WRITE_DATABASE"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths" />
    </provider>
0 Answers
Related