FileProvider Not Working with Camera

a 夏天 提交于 2019-11-28 05:14:07
You Qi
  1. Please do not try to put exported="true" as pointed out by pskink, your app will crash the moment it loads. FileProvider is not meant to work in this state.

  2. Tried intent.addFlags solution by CommonsWare. Not working. probably will only works with ACTION_SEND kind of intent.

  3. I found the answer in this post. Apparently the manual granting way is the only solution. But we can always loop thru the list of candidate packages and grantPermission to all of them.

    List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    for (ResolveInfo resolveInfo : resInfoList) {
        String packageName = resolveInfo.activityInfo.packageName;
        context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }
    

I had a similar issue but later on I find out to have a typo in my code. The typo was in AndroidManifest.xml, precisely into the tag at the line "authorities".

For me,

android:authorities="com.stackoverflow.test.camerawithfileprovider.fileprovider"

doesn't work (when I call the camera instance, the app crashes) but if i delete "file" and replace that string as following:

android:authorities="com.stackoverflow.test.camerawithfileprovider.provider"

my app runs smoothly (the app takes the photo, stores it, and gives back a preview to the activity in the client app).

Does your app also have the same issue ?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!