googlesamples / easypermissions

Simplify Android M system permissions
https://firebaseopensource.com/projects/googlesamples/easypermissions/
Apache License 2.0
9.87k stars 1.46k forks source link

onPermissionGranted not being called after permission have been granted and @AfterPermissionGranted not working either #254

Closed yankarinRG closed 6 years ago

yankarinRG commented 6 years ago

Basic Information

Device type: Nexus 5X (emulator) OS version: Android 9.0 EasyPermissions version: 2.0.0

Describe the problem

After both ACCESS_FINE_LOCATION and RECEIVE_SMS have been granted, onPermissionGranted is not being called. Using @AfterPermissionGranted, is not working either.

Code and logs

`public class LaunchScreenActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks, EasyPermissions.RationaleCallbacks {

private static final String TAG = LaunchScreenActivity.class.getSimpleName();
private static final int RC_LOCATION_AND_SMS = 0;
private static final String[] LOCATION_AND_SMS = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.RECEIVE_SMS};

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.AppThemeTest);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launch_screen);
    startMainActivity();
}

private void startMainActivity() {
    Log.d(TAG, "in startMainActivity");
    if (EasyPermissions.hasPermissions(this, LOCATION_AND_SMS)) {
        Log.d(TAG, "in startMainActivity/if");
        startActivity(new Intent(this, MainActivity.class));
        finish();
    } else {
        Log.d(TAG, "in startMainActivity/else");
        EasyPermissions.requestPermissions(this, "Rationale LOCATION_AND_SMS", RC_LOCATION_AND_SMS, LOCATION_AND_SMS);
    }
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults); // < i forgot the last parameter, this.
}

@Override
public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
    Log.d(TAG, "onPermissionsGranted:" + requestCode + ":" + perms.size());
    if (requestCode == RC_LOCATION_AND_SMS) {startMainActivity();}
    startMainActivity();
}`