您能为此提供建议吗?
我真的不明白为什么这个问题不清楚。
这是我来自android studio的错误消息。
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://media/external/images/media/7853 flg=0x1 (has extras) }} to activity {com.alibaba.food/com.alibaba.food.market.MarketRegActivity}: java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/food/msg/tmp_1542878122647.jpg
at android.app.ActivityThread.deliverResults(ActivityThread.java:4491)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4534)
at android.app.ActivityThread.-wrap20(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1752)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6940)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/food/msg/tmp_1542878122647.jpg
at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:738)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:417)
at com.alibaba.food.market.MarketRegActivity.createSaveCropFile(MarketRegActivity.java:447)
at com.alibaba.food.market.MarketRegActivity.onActivityResult(MarketRegActivity.java:337)
at android.app.Activity.dispatchActivityResult(Activity.java:7556)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4487)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4534)
at android.app.ActivityThread.-wrap20(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1752)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6940)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
我通常在21构建版本以下工作。 这是我第一次建立超过26岁的游戏。
我的文件provider.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path name="files" path="images/media/" /> <!-- Context.getFilesDir(). -->
<cache-path name="images" path="./images" /><!-- getCacheDir(). -->
<external-path name="name" path="path" /> <!-- Environment.getExternalStorageDirectory(). -->
<external-files-path name="storage/emulated" path="food/msg/" /> <!-- Context#getExternalFilesDir(String) Context.getExternalFilesDir(null). -->
<external-cache-path name="storage/emulated" path="." /> <!-- Context.getExternalCacheDir(). -->
</paths>
我的uri Java代码:
File dir = new File(Environment.getExternalStorageDirectory().getPath() + "/food/msg/");
if (!dir.mkdirs()) {
dir.mkdir();
}
Uri uri;
String url = "tmp_" + String.valueOf(System.currentTimeMillis()) + ".jpg";
filename = url;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // API 24 +..
String strpa = getApplicationContext().getPackageName();
uri = FileProvider.getUriForFile(getApplicationContext(),
getApplicationContext().getPackageName() + ".fileprovider",
new File(Environment.getExternalStorageDirectory().getPath()
+ "/food/msg/" + url));
} else {
uri = Uri.fromFile(
new File(Environment.getExternalStorageDirectory().getPath()
+ "/food/msg/" + url));
}
我的清单:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.alibaba.food.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
答案 0 :(得分:0)
添加到清单
classpath 'com.google.gms:google-services:4.2.0'
更改授权机构名称