Meh*_*iya 5 android android-fileprovider snapchat
我已经在我的Android应用程序中集成了Snapchat的Creative Kit。处理之后,我从服务器收到了字节数组形式的图像,将其保存到磁盘,然后将文件发送到Snapchat的Creative Kit,如下所示。
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)
}
}
Run Code Online (Sandbox Code Playgroud)
我还添加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>
Run Code Online (Sandbox Code Playgroud)
在中provider_paths_app.xml,我通过引用此答案尝试了所有可能的路径,但没有一个起作用。
<?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>
Run Code Online (Sandbox Code Playgroud)
通过上面的路径,我得到下面的错误。
Couldn't find meta-data for provider with authority my.package.name.fileprovider
Run Code Online (Sandbox Code Playgroud)
我所要做的就是将此图像发送到Snapchat,但我无法弄清楚自己在做什么错。任何帮助将不胜感激。
Pra*_*mar 83
首先在manifest中的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>
Run Code Online (Sandbox Code Playgroud)
然后在 res 中创建一个 xml 文件夹并创建一个文件名:provide+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="." />
</paths>
Run Code Online (Sandbox Code Playgroud)
现在大多数开发人员在程序中错误地在程序中创建文件然后我们将使用:
FileProvider.getUriForFile(Objects.requireNonNull(getApplicationContext()),
BuildConfig.APPLICATION_ID + ".provider", file);
Run Code Online (Sandbox Code Playgroud)
希望这对你有用!!!
ula*_*gor 10
如果构建的后缀不同,则进行这样的更改是有意义的。
FileProvider.getUriForFile(mContext.get(), BuildConfig.APPLICATION_ID + ".fileprovider", file)
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)
This is my provider declaration, the value of ${application} is "com.limxtop.research", make sure that the name of authorities is the same with that of the codes below.
// Create the file where the photo should save.
File file = null;
try {
file = createImageFile();
} catch (IOException e) {
break;
}
// The second parameter is the name of authorities.
Uri uri = FileProvider.getUriForFile(this,
"com.limxtop.research.fileprovider", file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(intent, fullSizeRequestCode);
Run Code Online (Sandbox Code Playgroud)
So, maybe your codes post here is not complete, there you should pass "my.package.name.fileprovider" as parameter some where.
小智 9
这里的问题是,您在清单中使用类名.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
Run Code Online (Sandbox Code Playgroud)
只需将 fileprovider 重命名为provider
就我而言。
我有一个图书馆项目。我们称之为:LibApk
当我对此进行编码时: build.grale(app) 中的 applicationId "my.package.name"
构建 gradle 时告诉我:库项目无法设置 applicationId。
applicationId 在默认配置中设置为“com.darcy.apkupdate”。
所以,我删除了 applicationId "my.package.name" 。
但我忘记更新使用${applicationId}的 AndroidManifest.xml 文件
这就是问题!!!
在这之后,这是我的锅!
希望这对你有帮助...
就我而言;
清单文件:
<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>
Run Code Online (Sandbox Code Playgroud)
代码:
import androidx.multidex.BuildConfig // NOT DO THIS!!!
val uri = FileProvider.getUriForFile(this,
BuildConfig.APPLICATION_ID+ ".provider", _tempFile)
Run Code Online (Sandbox Code Playgroud)
例外:
java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority androidx.multidex.provider
Run Code Online (Sandbox Code Playgroud)
不要使用 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() {
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4140 次 |
| 最近记录: |