class MainActivity : FlutterActivity() {

I then call this inside one of the functions of MainActivity:

            ActivityCompat.requestPermissions(
                    activity,
                    arrayOf(Manifest.permission.RECORD_AUDIO),
                    MY_PERMISSIONS_RECORD_AUDIO
            )

However, when I call it, instead of simply showing the microphone permission popup, it restarts the flutter activity and then shows the popup.

How can I make it just show the popup?


Solution 1: dumazy

You should avoid asking the permission within the MainActivity. The easiest way would be to use the permission_handler Flutter package and call it from your Flutter/Dart code.

if(await Permission.microphone.request().isGranted) {
  // use microphone
}

This will request the permission and execute the block within the curly braces if the user has granted it.