【发布时间】:2020-03-20 11:52:58
【问题描述】:
我们正在尝试访问我们正在构建的 Kivy 应用中的 Android 摄像头。我们首先选择使用plyer,但我们收到了ClipData.Item.getUri() 错误。我们最终尝试遵循此处描述的详细信息:https://github.com/kivy/plyer/issues/500#issuecomment-565532048
现在获取文件的 URI 似乎有问题。
我们在AndroidManifest.tmpl.xml添加了这个:
<manifest>
<application>
...
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="org.our.appnamehere"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
</application>
</manifest>
file_paths.xml 中也有这个:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="Android/data/org.our.appnamehere/files/Pictures" />
</paths>
我们已尝试将android:authorities 行更改为org.our.appnamehere.provider 和org.our.appnamehere.fileprovider,并从上面的链接更改给定文件中对应的getUriForFile
...
photo_file = self._create_image_file()
if photo_file is not None:
photo_uri = FileProvider.getUriForFile(
self.currentActivity.getApplicationContext(),
self.currentActivity.getApplicationContext().getPackageName(),
photo_file
)
...
进入self.currentActivity.getApplicationContext().getPackageName() + '.provider' 或self.currentActivity.getApplicationContext().getPackageName() + '.fileprovider'。
该应用似乎成功地创建了photo_file 链接到的文件,因为我们可以在Android/data/org.our.appnamehere/files/Pictures 下访问它们。我们总是收到以下错误,大概来自photo_uri 行:
JavaException("JVM Exception occurred: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference")
我们运行已编译应用程序的智能手机是 Android Pie,版本 9。
几乎所有针对此错误的解决方案都与我们添加到清单和 file_paths.xml 中的解决方案类似。除了android:authorities 的几种变体之外,我们还尝试了此链接中的以下几行:https://github.com/jkwiecien/EasyImage/issues/103#issuecomment-304304045
<provider
...
tools:replace="android:authorities">
<meta-data
...
tools:replace="android:resource"/>
</provider>
它们并没有真正起作用,我们仍然无法访问相机。我们可能只是遗漏了一些明显的东西......
任何帮助将不胜感激。非常感谢。
【问题讨论】:
-
我在 .apk 中打开了 AndroidManifest.xml,似乎提供程序标签根本不存在...
标签: java python android kivy uri