【发布时间】:2020-02-06 18:39:04
【问题描述】:
我正在尝试更新 ANE(Adobe 原生扩展)以在 Android 上使用我的 Adobe AIR 应用程序,但我似乎无法为文件获取正确的 FILE_PROVIDER_PATHS。
我将文件下载到我的 Adobe Flex 应用程序中的应用程序的 File.applicationStorageDirectory。
我在 Android 清单中的 FileProvider 如下所示:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="air.MY_APP_ID_HERE.files"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/fileproviderpaths" />
</provider>
fileproviderpaths.xml:
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="files" path="." />
<external-path name="files" path="." />
<external-files-path name="files" path="." />
</paths>
然后在 ANE (Java) 代码中,我尝试像这样访问文件:
newFile = new File(urlString);
// newFile.getPath() debugs as "/data/user/0/air.MY_APP_ID_HERE/MY_APP_ID_HERE/LocalStore/myFileName.apk"
// the file really exists there - i see it on newFile.exists() and newFile.length()
// context.getActivity() just returns the Android Context - this is Adobe AIR specific
// context.getActivity().getPackageName() debugs as "air.MY_APP_ID_HERE"
Uri fileUri = FileProvider.getUriForFile(context.getActivity(), context.getActivity().getPackageName() + ".files", newFile);
无论我在 fileproviderpaths.xml 中尝试什么,我总是遇到异常
Failed to find configured root that contains /data/data/air.MYAPP_ID_HERE/MYAPP_ID_HERE/Local Store/myFileName.apk
现在我的主要问题是为什么它在 newFile.getPath() 中称为“/data/user/0/air.MY_APP_ID_HERE...”,而在FileProvider 异常?
第二个问题是如何使用 Fileprovider 到达“/data/user/0/air.MY_APP_ID_HERE/MY_APP_ID_HERE/LocalStore/myFileName.apk”或如何在 fileproviderpaths.xml 中为其设置路径
感谢您的宝贵时间!
【问题讨论】:
-
newFile = new File(urlString);那么 urlString 的值是多少?你应该从那开始。请编辑您的代码。 -
fileUri.toSTring() 的值是多少?
-
"/data/user/0/air.MY_APP_ID_HERE/MY_APP_ID_HERE/LocalStore/myFileName.apk"。我认为目录/data/user/0/air.MY_APP_ID_HERE将不存在。但我不知道空气。目录/data/user/0/MY_APP_ID_HERE可能存在。那将是您的应用程序私有内部存储器。 -
FileProvider 需要 getFilesDir() 或其子目录中的文件。 getFilesDir().getAbsolutePath() 的值是多少?
-
<files-path name="files" path="." /> <external-path name="files" path="." /> <external-files-path name="files" path="." />我不会给他们三个名字files。
标签: android apache-flex air android-fileprovider ane