Android:IllegalArgumentException:无法找到包含/data/data/的配置的根 [英] Android: IllegalArgumentException: Failed to find configured root that contains /data/data/

查看:163
本文介绍了Android:IllegalArgumentException:无法找到包含/data/data/的配置的根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只需进入Android的Glide图片加载库即可. 从此处使用代码: https://github.com/bumptech/glide/issues/459

Just getting into the Glide image loading library for Android. Working with code from here: https://github.com/bumptech/glide/issues/459

此处的完整项目: https://github.com/mhurwicz/glide02

在Android Studio的模拟器中运行应用程序时,出现以下异常:

I'm getting the following exception when I run the app in the emulator in Android Studio:

java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.example.glide02/cache/image_manager_disk_cache/5a992029460eed14244e8b970d969d45518b2f7ac10f71eb26bd0aaf7c3bcf06.0

其余消息为:

at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:711)
                  at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400)
                  at com.example.glide02.ShareTask.onPostExecute(ShareTask.java:37)
                  at com.example.glide02.ShareTask.onPostExecute(ShareTask.java:15)
                  at android.os.AsyncTask.finish(AsyncTask.java:651)
                  at android.os.AsyncTask.-wrap1(AsyncTask.java)
                  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:148)
                  at android.app.ActivityThread.main(ActivityThread.java:5417)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

错误发生在FileProvider.getUriForFile()

The error occurs on FileProvider.getUriForFile()

@Override protected void onPostExecute(File result) {
    if (result == null) { return; }
    Uri uri = FileProvider.getUriForFile(context, context.getPackageName(), result);
    share(uri); // startActivity probably needs UI thread
}

我已经查看了与该错误有关的其他几个问题,但由于我对整个领域缺乏了解,因此看不到它们与我的案件有何关系.

I've looked at several other questions relating to this error, but can't see how they relate to my case, perhaps due to my lack of familiarity with this whole area.

任何帮助将不胜感激.

这是发生上述方法的类的完整代码:

This is the full code for the class in which the above method occurs:

class ShareTask extends AsyncTask<String, Void, File> {
private final Context context;

public ShareTask(Context context) {
    this.context = context;
}
@Override protected File doInBackground(String... params) {
    String url = params[0]; // should be easy to extend to share multiple images at once
    try {
        return Glide
                .with(context)
                .load(url)
                .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
                .get() // needs to be called on background thread
                ;
    } catch (Exception ex) {
        Log.w("SHARE", "Sharing " + url + " failed", ex);
        return null;
    }
}
@Override protected void onPostExecute(File result) {
    if (result == null) { return; }
    Uri uri = FileProvider.getUriForFile(context, context.getPackageName(), result);
    share(uri); // startActivity probably needs UI thread
}

private void share(Uri result) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("image/jpeg");
    intent.putExtra(Intent.EXTRA_SUBJECT, "Shared image");
    intent.putExtra(Intent.EXTRA_TEXT, "Look what I found!");
    intent.putExtra(Intent.EXTRA_STREAM, result);
    context.startActivity(Intent.createChooser(intent, "Share image"));
}

}

推荐答案

filepaths.xml中,您需要

<cache-path name="shared_images_from_glide_cache" path="image_manager_disk_cache"/>

这将导致映射

new File("/data/data/com.example.glide02/cache/image_manager_disk_cache/5a992029460eed14244e8b970d969d45518b2f7ac10f71eb26bd0aaf7c3bcf06.0")

Uri.parse("content://com.example.glide02/shared_images_from_glide_cache/5a992029460eed14244e8b970d969d45518b2f7ac10f71eb26bd0aaf7c3bcf06.0")

(不确定我是否完全正确,但是您应该明白这一点.)

(Not sure if I got it exactly right, but you should get the point.)

这篇关于Android:IllegalArgumentException:无法找到包含/data/data/的配置的根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆