permissions-dispatcher / PermissionsDispatcher

A declarative API to handle Android runtime permissions.
https://github.com/permissions-dispatcher/PermissionsDispatcher
Apache License 2.0
11.21k stars 1.44k forks source link

Android Fragment permission dispatcher request.proceed() not working #695

Closed koushikv04 closed 3 years ago

koushikv04 commented 3 years ago

FAQs

@RuntimePermissions public class MyFragment extends Fragment implements ConnectivityReceiver.ConnectivityReciverListener{

@NeedsPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
void showLocation() {
    Log.d("Permission", "Show location");
}

@OnShowRationale(Manifest.permission.ACCESS_COARSE_LOCATION)
void showRationaleForLocation(final permissions.dispatcher.PermissionRequest request) {
    new AlertDialog.Builder(getActivity())
            .setMessage("We really need the location permission")
            .setPositiveButton("Allow", (dialog, button) -> request.proceed())
            .setNegativeButton("Deny", (dialog, button) -> request.cancel())
            .show();

}

@OnPermissionDenied(Manifest.permission.ACCESS_COARSE_LOCATION)
void showDeniedForLocation() {
    Toast.makeText(getActivity(), "location permission denied", Toast.LENGTH_SHORT).show();
}

@OnNeverAskAgain(Manifest.permission.ACCESS_COARSE_LOCATION)
void showNeverAskForLocation() {
    Toast.makeText(getActivity(), "show never ask for location again", Toast.LENGTH_SHORT).show();
}

Build.gradle

apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services'

android { compileSdkVersion 29 buildToolsVersion "29.0.2"

defaultConfig {
    applicationId "com.example.sampleApp"
    minSdkVersion 21
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

}

buildscript { repositories { google() } dependencies { classpath 'com.google.gms:google-services:4.0.0' } }

dependencies { implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
implementation 'com.sweepr.android:mobile-framework:0.1.5'
implementation 'io.sweepr.client:sweepr-api:0.1.7'
implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// handle permissions hell
implementation "org.permissionsdispatcher:permissionsdispatcher:4.8.0"
annotationProcessor "org.permissionsdispatcher:permissionsdispatcher-processor:4.8.0"

implementation "com.google.firebase:firebase-core:17.5.1"
implementation "com.google.firebase:firebase-messaging:20.3.0"

}


Overview

I've added the permission dispatcher in my application. I am using to get user location permission. It shows the alert dialog but the show location function is not called when i press on allow in alert dialog i.e request.proceed() does not call the showLocation() method. It is called when i call grant permission the second time.

Expected

it should call showLocation method to proceed further

Actual

it only only works second time when i ask for permission again

Environment

Reproducible steps

I just call the permission check SweeprFragmentPermissionsDispatcher.showLocationWithPermissionCheck(this); which inturn calls the permission dispatcher

hotchemi commented 3 years ago

request.proceed() shows permission dialog and it does not call NeedsPermission annotated method. this is the expected behahviour. @koushikv04