FileProvider Not Working with Camera

后端 未结 2 747
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 06:07

I\'m trying to make Camera App to store the output to my internal storage. I also understand that third party apps are not able to access the Internal Storage of my applicat

2条回答
  •  天命终不由人
    2020-12-08 06:53

    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 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);
      }
      

提交回复
热议问题