react-native-call-detection/android/src/main/java/com/pritesh/calldetection/CallDetectionManagerModule.java
@ReactMethod
    public void requestPermission(final String permission, final Promise promise) {

        try {

            if(_checkPermission(permission)) {
                
                promise.resolve(GRANTED);
                return;
            } else if( Build.VERSION.SDK_INT < Build.VERSION_CODES.M ){

                promise.resolve(DENIED);
                return;
            }

            PermissionAwareActivity activity = getPermissionAwareActivity();

            mCallbacks.put(
                mRequestCode, 
                new Callback() {

                    @Override
                    public void invoke(Object... args) {

                        int[] results = (int[]) args[0];

                        if (results.length > 0 && results[0] == PackageManager.PERMISSION_GRANTED) {
                            promise.resolve(GRANTED);
                        } else {
                            PermissionAwareActivity activity = (PermissionAwareActivity) args[1];
                            if (activity.shouldShowRequestPermissionRationale(permission)) {
                                promise.resolve(DENIED);
                            } else {
                                promise.resolve(NEVER_ASK_AGAIN);
                            }
                        }
                    }
                }
            );

            activity.requestPermissions(new String[]{permission}, mRequestCode, this);
            mRequestCode++;
        } catch (IllegalStateException e) {

            promise.reject("ERROR INVALID ACTIVITY", e);
        } catch(Exception e) {

            promise.reject("ERROR Request permistion", e);
        }
    }
/**
    * Request the given permission. successCallback is called with true if the permission had been
    * granted, false otherwise. For devices before Android M, this instead checks if the user has
    * the permission given or not.
    * See {@link Activity#checkSelfPermission}.
    */
Request the given permission. successCallback is called with true if the permission had been
granted, false otherwise. For devices before Android M, this instead checks if the user has
the permission given or not.
Request the given permission . successCallback is called with true if the permission had been granted false otherwise . For devices before Android M this instead checks if the user has the permission given or not .
@ReactMethod
    public void requestPermission(final String permission, final Promise promise) {
        try {
            if(_checkPermission(permission)) {
                promise.resolve(GRANTED);
                return;
            } else if( Build.VERSION.SDK_INT < Build.VERSION_CODES.M ){
                promise.resolve(DENIED);
                return;
            }
            PermissionAwareActivity activity = getPermissionAwareActivity();
            mCallbacks.put(
                mRequestCode, 
                new Callback() {
                    @Override
                    public void invoke(Object... args) {
                        int[] results = (int[]) args[0];
                        if (results.length > 0 && results[0] == PackageManager.PERMISSION_GRANTED) {
                            promise.resolve(GRANTED);
                        } else {
                            PermissionAwareActivity activity = (PermissionAwareActivity) args[1];
                            if (activity.shouldShowRequestPermissionRationale(permission)) {
                                promise.resolve(DENIED);
                            } else {
                                promise.resolve(NEVER_ASK_AGAIN);
                            }
                        }
                    }
                }
            );
            activity.requestPermissions(new String[]{permission}, mRequestCode, this);
            mRequestCode++;
        } catch (IllegalStateException e) {
            promise.reject("ERROR INVALID ACTIVITY", e);
        } catch(Exception e) {
            promise.reject("ERROR Request permistion", e);
        }
    }
@ ReactMethod public void requestPermission ( final String permission , final Promise promise ) { try { if ( _checkPermission ( permission ) ) { promise . resolve ( GRANTED ) ; return ; } else if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . M ) { promise . resolve ( DENIED ) ; return ; } PermissionAwareActivity activity = getPermissionAwareActivity ( ) ; mCallbacks . put ( mRequestCode , new Callback ( ) { @ Override public void invoke ( Object ... args ) { int [ ] results = ( int [ ] ) args [ 0 ] ; if ( results . length > 0 && results [ 0 ] == PackageManager . PERMISSION_GRANTED ) { promise . resolve ( GRANTED ) ; } else { PermissionAwareActivity activity = ( PermissionAwareActivity ) args [ 1 ] ; if ( activity . shouldShowRequestPermissionRationale ( permission ) ) { promise . resolve ( DENIED ) ; } else { promise . resolve ( NEVER_ASK_AGAIN ) ; } } } } ) ; activity . requestPermissions ( new String [ ] { permission } , mRequestCode , this ) ; mRequestCode ++ ; } catch ( IllegalStateException e ) { promise . reject ( "ERROR INVALID ACTIVITY" , e ) ; } catch ( Exception e ) { promise . reject ( "ERROR Request permistion" , e ) ; } }
Request the given permission.
Request the given permission .