Request runtime permissions from v4.Fragment and have callback go to Fragment? Request runtime permissions from v4.Fragment and have callback go to Fragment? java java

Request runtime permissions from v4.Fragment and have callback go to Fragment?


Adding this to the parent activity works for me:

@Overridepublic void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {    super.onRequestPermissionsResult(requestCode, permissions, grantResults);    List<Fragment> fragments = getSupportFragmentManager().getFragments();    if (fragments != null) {        for (Fragment fragment : fragments) {            fragment.onRequestPermissionsResult(requestCode, permissions, grantResults);        }    }}

Source: https://code.google.com/p/android/issues/detail?id=189121#c5


If you need to get the permissionResult in fragment v4 make sure you use

Fragment.requestPermission(String[], int);

instead of

AppCompat.requestPermission(Activity, String[], int)

Check out this answer!


This behavior seems to be present in the v4 Fragment support class requestPermissions in Fragment. The Activity/FragmentCompat implementations exist for people who wish to use the native classes with the extended functionality on API levels between 11 and 23.