[英]Android Files: if I copy a .zip file to /sdcard/Download, the uri will be wrong
我要求我们可以通过我的应用程序打开 .zip 文件(替换为 .activity)。 我将 manifest.xml 设置为
<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>
当我用下面的代码打开一个名为“test.activity”的文件时,它实际上是“test.zip”。
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);
首先,我将“test.activity”推送到 /sdcard/Download,然后我得到了一个类似content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2Ftest.activity
的 uri
然后我单击“下载”并将文件也复制到“下载”(/sdcard/Download),它将自动以 test(1).activity 命名。 我认为正确的uri应该是
content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2Ftest(1).activity
但我有一个像
content://com.android.providers.downloads.documents/document/805
所以我一开始提到的'intent-filter'就会失效。 谁能告诉我为什么这个 uri 的结尾变成了一个数字?
在某些设备上。 从下载目录中选择文件时将返回错误的 uri。 所以你需要改变它
你可以参考这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.