Android 不能';找不到具有权限的提供程序的元数据
我已经在我的Android应用程序中集成了Snapchat的创意工具包。处理后,我从服务器接收到一个字节数组形式的图像,并将其保存到磁盘,然后将该文件发送到Snapchat的创作工具包,如下所示Android 不能';找不到具有权限的提供程序的元数据,android,android-fileprovider,snapchat,Android,Android Fileprovider,Snapchat,我已经在我的Android应用程序中集成了Snapchat的创意工具包。处理后,我从服务器接收到一个字节数组形式的图像,并将其保存到磁盘,然后将该文件发送到Snapchat的创作工具包,如下所示 private fun downloadImage( fileName: String, imageByteArray: ByteArray?): Uri? { val state = Environment.getExternalStorageState() if
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
,如下所示:
<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>
通过上面的路径,我得到下面的错误
Couldn't find meta-data for provider with authority my.package.name.fileprovider
我所要做的就是将此图像发送到Snapchat,但我无法找出我做错了什么。任何帮助都将不胜感激
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
因此,可能您在此处发布的代码不完整,您应该在此处将“my.package.name.fileprovider”作为参数传递给某些地方。将权限更改为唯一名称以解决以下问题:
android:authorities=“${applicationId}.myUniquefileprovider”
同样在java代码中,首先在manifest中的标记下写入以下标记
<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>
希望这对你有用 mImageFromCamera=FileProvider.getUriForFile(这是BuildConfig.APPLICATION_ID+“FileProvider”,mImageFile);
android:Authories=“${applicationId}.文件提供者”
权限在xml和代码中必须相同我刚刚从android中删除了“$”authorities=“${applicationId}.provider”,现在它就像一个符咒一样工作。在我的例子中 我有一个图书馆项目,我们称之为:LibApk 当我编写此代码时:build.grale(应用程序)中的applicationId“my.package.name” 构建gradle时告诉我:库项目无法设置applicationId。 applicationId在默认配置中设置为'com.darcy.apkupdate'。 因此,我删除了applicationId“my.package.name” 然后,build.gradle如下所示: 但是我忘了更新AndroidManifest.xml文件,该文件使用${applicationId} 这就是问题所在 因此,我将变量更改为常量。结果如下图所示: 在这之后,我的工作就结束了
希望这是对您有帮助的…它的文件提供者而不是提供者
android:authorities="${applicationId}.fileprovider"
{applicationId}
=com.companyName.application
附加“.provider”
它将是==com.example.test.provider
在xmlauthorities:com.example.test.provider中
在activityurimpath=FileProvider.getUriForFile中(这是“com.example.example.provider”,imageFile)代码>这里的问题是,对于清单中的权限,您使用类名.provider
并在java代码中使用.fileprovider类名
<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>
Couldn't find meta-data for provider with authority my.package.name.fileprovider
找不到具有权限my.package.name.fileprovider的提供程序的元数据
在我的例子中,只需将fileprovider重命名为provider
清单文件:
<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>
例外情况:
java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority androidx.multidex.provider
不要使用androidx.multidex.BuildConfig,因为这些值不是我们应用程序的值:
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package androidx.multidex;
public final class BuildConfig {
public static final boolean DEBUG = false;
public static final String APPLICATION_ID = "androidx.multidex";
public static final String BUILD_TYPE = "release";
public static final String FLAVOR = "";
public static final int VERSION_CODE = -1;
public static final String VERSION_NAME = "";
public BuildConfig() {
}
}
首先你使用
文件(getExternalFilesDir(null),context?.getString(R.string.app_name))代码>
而不是
Environment.getExternalStorageDirectory(),context?.getString(R.string.app_name)//这在API29中已被弃用
那就用这个
uricontenturi=getUriForFile(getContext(),“com.mydomain.fileprovider”,newFile)代码>
有关更多帮助:如果生成的后缀不同,则进行如下更改是有意义的
FileProvider.getUriForFile(mContext.get(), BuildConfig.APPLICATION_ID + ".fileprovider", file)
。卸载旧版本。@IntelliJAmiya现在,出现以下错误:未能找到包含/storage/emulated/0/My App Name/image的配置根目录。jpgI在我的每个生成类型文件夹(开发、暂存和发布)上使用了不同的清单,以便我可以在我的提供程序上设置不同的权限。使用${applicationId}变量,我可以再次将清单文件统一到单个清单文件中。很好的解释谢谢你。。我尝试了所有其他的解决方案,但是BuildConfig.APPLICATION\u ID+“.provider”
是它最终对我起作用的原因。对我来说,问题是区分大小写。我将.FileProvider
放在一个位置,将.FileProvider
放在另一个位置。这个案子必须相符!我尝试构建config.APPLICATION_ID+“.provider”是它最终能够从.provider机械化到.fileprovider的原因,解决了我的问题。谢谢@ulaserdegor
<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>
import androidx.multidex.BuildConfig // NOT DO THIS!!!
val uri = FileProvider.getUriForFile(this,
BuildConfig.APPLICATION_ID+ ".provider", _tempFile)
java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority androidx.multidex.provider
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package androidx.multidex;
public final class BuildConfig {
public static final boolean DEBUG = false;
public static final String APPLICATION_ID = "androidx.multidex";
public static final String BUILD_TYPE = "release";
public static final String FLAVOR = "";
public static final int VERSION_CODE = -1;
public static final String VERSION_NAME = "";
public BuildConfig() {
}
}
FileProvider.getUriForFile(mContext.get(), BuildConfig.APPLICATION_ID + ".fileprovider", file)