0

I would like to know whether the runtime permission popup is visible or not in the activity. How can i know that? Is there any callback or overrided method for the same.

Jiju Induchoodan
  • 4,236
  • 1
  • 22
  • 24

1 Answers1

1

You request permissions yourself so you know when it is shown. You can also add a result callback. See the code below;

public void requestPermissions(List<String> permissions, ActivityCompat.OnRequestPermissionsResultCallback onRequestPermissionsResultCallback) {
    String[] params = permissions.toArray(new String[permissions.size()]);
    requestPermissions(params, onRequestPermissionsResultCallback);
}

public void requestPermissions(String[] permissions, ActivityCompat.OnRequestPermissionsResultCallback onRequestPermissionsResultCallback) {
    this.onRequestPermissionsResultCallback = onRequestPermissionsResultCallback;
    ActivityCompat.requestPermissions(this, permissions, REQUEST_CODE_PERMISSIONS);
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    if (requestCode == REQUEST_CODE_PERMISSIONS && onRequestPermissionsResultCallback != null) {
        this.onRequestPermissionsResultCallback.onRequestPermissionsResult(requestCode, permissions, grantResults);
        this.onRequestPermissionsResultCallback = null;
    }
}

This would generally sit inside some kind of base Activity class.

vguzzi
  • 2,420
  • 2
  • 15
  • 19
  • No i have added some libraries to my app, and this library shows the runtime permission popup and dont have control on my application code. So in that case how can I know the popup is on the activity or not – Jiju Induchoodan Mar 30 '16 at 16:09
  • You'll have to look at the library documentation to see if they have added the ability for you to get that information. The logic is so simple there is almost no need for a library. – vguzzi Mar 30 '16 at 16:30
  • The library i am using is not for runtime permission, it is actually for push notification and ads. Those two libraries are using the permissions. – Jiju Induchoodan Mar 30 '16 at 16:37