0

I want to download a file to the Downloads directory and then view it when the user wants to open it. I am able to save the file to the downloads directory, but the problem arises when I try to view it using an Intent Chooser. At first, I saw the file gets saved with the path: storage/emulated/0/Download/filename but I wasn't aware how to access this path for different versions of devices, so I got the answer for this question from the question i posted earlier here.

Now, I am able to view the file as well since I'm aware of the filename, it's mimetype, and the path from the above explanation. But, the problem is, I am only able to view the file via the Intent Chooser for devices like Google Pixel and Samsung m 30s running on Android 10, and when I tried for devices like Realme 3 Pro, Oneplus 6 and some MI device that were also running on Android 10, after an app is selected from the Intent Chooser, instead of opening the file on these devices it tries to open the file but then jumps back to my app without opening the file. For devices below Android 10 the problem doesn't seem to exist to me.

The code for my DownloadRepository and MainActivity can be found in the Github gists here and here respectively.

I am currently not attaching code for the FileProvider in the Android Manifest and the provider_paths in the XML since it is working for some devices but I can attach that too if needed :)

EDIT

here is my Android Manifest and the path for FileProvider:

Android Manifest permissions and FileProvider

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="28" />
<uses-permission 
android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />

<provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="${applicationId}.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />
    </provider>

file_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
    name="downloads"
    path="/Download" />
</paths>
mehul bisht
  • 682
  • 5
  • 15

1 Answers1

0

I don't think the Intent chooser is used to open the file . You can use Intent(ACTION_VIEW) and set its data and type with flags

Hope this answers might help ACTION_VIEW intent for a file with unknown MimeType

Daksh Semwal
  • 99
  • 2
  • 11
  • Well, did you open the Gist for `MainActivity` that I had linked? It already uses `Intent.ACTION_VIEW` with a specified `mimetype` but it works for some devices only. I have tested and found the problem only for real devices running on `Android 10`. – mehul bisht Jul 07 '21 at 12:36