找不到具有授权者的元数据 [英] Couldn't find meta-data for provider with authority
问题描述
我在我的Android应用中集成了Snapchat的Creative Kit.处理后,我从服务器收到了字节数组形式的图像,将其保存到磁盘,然后将文件发送到Snapchat的Creative Kit,如下所示.
I have integrated Snapchat's Creative Kit in my Android app. After processing, I receive an image from the server in the form of Byte Array which I am saving to the disk and then sending the file to the Snapchat's Creative Kit as shown below.
private fun downloadImage(
fileName: String,
imageByteArray: ByteArray?): Uri? {
val state = Environment.getExternalStorageState()
if (Environment.MEDIA_MOUNTED == state) {
val downloadDir = File(
Environment.getExternalStorageDirectory(), context?.getString(R.string.app_name)
)
if (!downloadDir.isDirectory) {
downloadDir.mkdirs()
}
val file = File(downloadDir, fileName)
var ostream: FileOutputStream? = null
try {
ostream = FileOutputStream(file)
ostream.write(imageByteArray)
ostream.flush()
ostream.close()
}
} catch (e: IOException) {
e.printStackTrace()
}
val snapCreativeKitApi = SnapCreative.getApi(context!!)
val snapMediaFactory = SnapCreative.getMediaFactory(context!!)
lateinit var snapPhotoFile: SnapPhotoFile
try {
snapPhotoFile = snapMediaFactory.getSnapPhotoFromFile(file)
} catch (e: SnapMediaSizeException) {
return
}
val snapPhotoContent = SnapPhotoContent(snapPhotoFile)
snapCreativeKitApi.send(snapPhotoContent)
}
}
我还在清单文件中添加了provider
,如下所示:
I have also added provider
in the manifest file as shown below:
<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/provider_paths_app" />
</provider>
在provider_paths_app.xml
中,我通过引用
And in the provider_paths_app.xml
, I have tried all the possible paths by referring this answer and none of them works.
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="My App Name"
path="." />
</paths>
使用上面的路径,我得到下面的错误.
With the above path, I am getting the below error.
Couldn't find meta-data for provider with authority my.package.name.fileprovider
我所要做的就是将此图像发送到Snapchat,但是我无法弄清楚我在做什么错.任何帮助将不胜感激.
All I have to do is send this image to Snapchat but I am unable to figure out what I am doing wrong. Any help will be appreciated.
推荐答案
首先在清单中的标签下写下以下标签
First write the following tag in manifest under the Tag
<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/provider_paths" />
</provider>
然后在res中创建一个xml文件夹并创建一个文件名:Provide + paths.xml 然后复制粘贴代码:
Then Create a xml folder in res and create a file names: provide+paths.xml and then copy paste the code:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="external_files"
path="." />
</paths>
,现在大多数开发人员都在程序中错误地在程序中创建File,那么我们将使用:
and now most developer mistake in programs to create File in program then we will use:
FileProvider.getUriForFile(Objects.requireNonNull(getApplicationContext()),
BuildConfig.APPLICATION_ID + ".provider", file);
希望这对您有用!
这篇关于找不到具有授权者的元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!