content: package com.abh80.smartedge.activities;
  
  import android.Manifest;
  import android.content.Intent;
  import android.content.pm.PackageManager;
  import android.net.Uri;
  import android.os.Bundle;
  import android.provider.Settings;
  import android.widget.CheckBox;
  import android.widget.Toast;
  
  import androidx.annotation.NonNull;
  import androidx.annotation.Nullable;
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.core.app.ActivityCompat;
  
  import com.abh80.smartedge.R;
  
  public class PermissionActivity extends AppCompatActivity {
      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_permission);
          findViewById(R.id.notification_access).setOnClickListener(l -> {
              if (Settings.Secure.getString(this.getContentResolver(), "enabled_notification_listeners") != null && Settings.Secure.getString(this.getContentResolver(), "enabled_notification_listeners").contains(getApplicationContext().getPackageName())) {
                  Toast.makeText(this, "This permission is already enabled", Toast.LENGTH_LONG).show();
                  return;
              }
              startActivity(new Intent(
                      "android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
              Toast.makeText(this, "Please select Smart Edge", Toast.LENGTH_LONG).show();
          });
          findViewById(R.id.record_audio).setOnClickListener(l -> {
              if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) {
                  Toast.makeText(this, "This permission is already enabled", Toast.LENGTH_LONG).show();
                  return;
              }
              ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, 101);
          });
      }
  
      @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
          super.onRequestPermissionsResult(requestCode, permissions, grantResults);
          onResume();
      }
  
      @Override
      protected void onResume() {
          super.onResume();
          int checks = 0;
          if (Settings.Secure.getString(this.getContentResolver(), "enabled_notification_listeners") != null && Settings.Secure.getString(this.getContentResolver(), "enabled_notification_listeners").contains(getApplicationContext().getPackageName())) {
              ((CheckBox) findViewById(R.id.notification_access_checkbox)).setChecked(true);
              checks++;
          }
          if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) {
              ((CheckBox) findViewById(R.id.record_audio_checkbox)).setChecked(true);
              checks++;
          }
          if (checks >= 2) {
              finish();
          }
      }
  }
  