0

I am using 3rd party screen recording library which has foreground service and when screen recording is started new post-notification permission dialog is shown by the system automatically on Android 13. Is there any way to register a listener to get data on whether that permission is granted or not?

I've tried to request post notification permission manually before the screen record starts, but the permission dialog is not shown after the request.

requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)  

Its all happening only on Android 13.

artois
  • 485
  • 1
  • 6
  • 13

3 Answers3

2

Requesting like this:

private void request_notification_api13_permission() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
        if (this.checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {

            ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.POST_NOTIFICATIONS}, 22);
        }
    }
}

checking results like this:

   @Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == 22) {
        if (grantResults.length > 0)
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {

               // permission granted, perform required code

            } else {
                // not granted
            }
    }
}

you can change number 22 to any number you want.

1
  • Declare the permission in your app's manifest file

     <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    
  • Request a permission from the user

    if (Build.VERSION.SDK_INT >= 33) {
    if (ContextCompat.checkSelfPermission(activity, POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) {
           requestPermissionLauncher.launch(POST_NOTIFICATIONS);
    
                } else {
                     //permission already granted
    
                  }
              }
    
  • Register the permissions callback, which handles the user's response to the system permissions dialog. Save the return value, an instance of ActivityResultLauncher, as an instance variable.

    private ActivityResultLauncher<String> requestPermissionLauncher =
              registerForActivityResult(new RequestPermission(), 
                       isGranted -> {
                  if (isGranted) {
                      // Permission is granted. Continue the action or workflow in your 
                          app.
                  } else {
                        // Explain to the user that the feature is unavailable because the
          // feature 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.
                  }
              });
    

Hope it will help!!

Kishan Thakkar
  • 619
  • 6
  • 11
0

Request for multiple permissions, Explain user why the permissions are needed, All Api included 33. Check my answer here.

Noor Hossain
  • 1,620
  • 1
  • 18
  • 25