onRequestPermissionsResult not being called in fragment if defined in both fragment and activity

前端 未结 15 1333
余生分开走
余生分开走 2020-11-28 22:14

I have a fragment in which I have recyclerview and setting data in this recyclerview using recyclerview adapter.

Now, I am having a button in the adapter\'s list ite

15条回答
  •  温柔的废话
    2020-11-28 22:36

    you can call the Fragment method below

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode) {
            case REQUEST_CODE:
                // If request is cancelled, the result arrays are empty.
                if (grantResults.length > 0 &&
                        grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    // Permission is granted. Continue the action or workflow
                    // in your app.
                    doActionBecauseNowYouCanBro();
                } else {
                    // Explain to the user that the feature is unavailable because
                    // the features requires a permission that the user has denied.
                    // At the same time, respect the user's decision. Don't link to
                    // system settings in an effort to convince the user to change
                    // their decision.
                    showWhyRequestPermissionsAndDontBlockUserItsCalledManners();
                }
                return;
        }
        // Other 'case' lines to check for other
        // permissions this app might request.
    
    }
    

提交回复
热议问题