1

I got a requirement that we can open a .zip file(replaced with .activity) through my app. I set the manifest.xml like

<intent-filter>
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.DEFAULT" />
     <data android:scheme="file" />
     <data android:scheme="content" />
     <data android:host="*" />
     <data android:mimeType="*/*" />
     <data android:pathPattern=".*\\.activity" />
</intent-filter>

When I open a file named 'test.activity' which is 'test.zip' actually with the code below.

public void chooseFile(CallbackContext callbackContext) {

        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.setType("*/*");
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);

First I push 'test.activity' to /sdcard/Download and I got a uri like content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2Ftest.activity

Then I click Downloads and copy the file to Downloads as well(/sdcard/Download), it will be named with test(1).activity automatically. I thought the correct uri should be

content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2Ftest(1).activity

but I got a uri like

content://com.android.providers.downloads.documents/document/805

So the 'intent-filter' I mentioned at the beginning will become invalid. Could anyone tell me why the end of this uri becomes a number?

Leon Chen
  • 11
  • 1
  • 3
  • `content://com.android.providers.downloads.documents/document/805` That is a pretty normal content scheme obtained from a Download 'partition'. A valid uri. That provider does it like that. Get used to it. – blackapps Dec 16 '19 at 12:01
  • The number is the document id of the file. – blackapps Dec 16 '19 at 12:09
  • Your approach can maybe work if you first make a folder in the Downloads and put your file there. Untested. – blackapps Dec 16 '19 at 12:11

1 Answers1

0

On some devices. when selecting a file from the download directory will return the wrong uri. So you need to change it

You can refer here

https://github.com/Turtlebody/android-media-picker/issues/7

Nguyễn Trung Hiếu
  • 2,004
  • 1
  • 10
  • 22