Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes in request permissions! #133

Open
yasersojoodi opened this issue Oct 27, 2023 · 1 comment
Open

App crashes in request permissions! #133

yasersojoodi opened this issue Oct 27, 2023 · 1 comment

Comments

@yasersojoodi
Copy link

yasersojoodi commented Oct 27, 2023

I/FA-Ads ( 8545): Application backgrounded at: timestamp_millis: 1698398144366
D/AndroidRuntime( 8545): Shutting down VM
E/AndroidRuntime( 8545): FATAL EXCEPTION: main
E/AndroidRuntime( 8545): Process: musicetapp.ir.musicet, PID: 8545
E/AndroidRuntime( 8545): java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=88560, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {musicetapp.ir.musicet/musicetapp.ir.musicet.MainActivity}: com.lucasjosino.on_audio_query.PluginProvider$UninitializedPluginProviderException: Tried to get one of the methods but the 'PluginProvider' has not initialized

@NikolaKuzmanovski
Copy link

NikolaKuzmanovski commented Feb 19, 2024

You should make sure that no rendered component executes audioQuery before getting users permission.
Ex.

bool permissionGranted = false;

  @override
  void initState() {
    super.initState();
    _requestPermission();
  }
  
  void _requestPermission() async {
    PermissionStatus status = await Permission.audio.request();

    if (status.isPermanentlyDenied) {
      await Permission.audio.request();
    }
    if (status.isGranted) {
      _createPlaylist();
      setState(() {
        permissionGranted = true;
      });
    }
  }

When permissionGranted = true you can initialise the audioQuerys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants