Why the grant of URI permissions to all resolving activities?


#1

@cstewart Why are we granting URI permission to all resolving activities via the following code block?

    List<ResolveInfo> cameraActivities = getActivity().getPackageManager()
                            .queryIntentActivities(captureImage, PackageManager.MATCH_DEFAULT_ONLY);

    for (ResolveInfo activity : cameraActivities) {
         getActivity().grantUriPermission(activity.activityInfo.packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    }

Is it make for a flexible app? i.e., to facilitate users select from their list of camera apps that they best feel would capture the image (perhaps one with custom filters, shaders, stickers, etc…,)?

I used the below code to pass uri permissions to the first activity from the list:

String packageName = packageManager.resolveActivity(
                        captureImage,
                        PackageManager.MATCH_DEFAULT_ONLY
                ).activityInfo.packageName;
getActivity().grantUriPermission(
                        packageName,
                        uri,
                        Intent.FLAG_GRANT_WRITE_URI_PERMISSION
);

#2

Yes, it’s so the user can choose any of the options (if they have more than one).