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

Crashing error on Android Auto - Requesting for Permissions and Querying for Audio when app is in Background. #159

Open
bensalcie opened this issue Nov 20, 2024 · 0 comments

Comments

@bensalcie
Copy link

bensalcie commented Nov 20, 2024

I am Building an app that needs to support Android Auto to play Device music. So what I do is to check permissions with Audio Query and retrieve a list of songs. Apparently when app is active and on Foreground, its able to show local songs correctly, but when user connects to Android Auto and App is in background, then its crashes the app on Android Auto and trying to Launch the app on the phone, leads to Plugin error as shown below:

Function to check and give permissions:

    Future<bool> _requestStoragePermission() async {
            try {
              final isGranted = await _audioQuery.permissionsStatus();
              if (!isGranted) {
                final requestResult = await _audioQuery.permissionsRequest();
                return requestResult; // Returns true if permissions are granted
              }
              return isGranted; // Permissions already granted
            } catch (e) {
              print("Error requesting storage permission: $e");
              return false; // Handle errors gracefully
            }
          }

Retrieve songs:

 final isStoragePermissionGranted = await _requestStoragePermission();
    if (isStoragePermissionGranted) {
      final audios = await _audioQuery.querySongs(
        sortType: null,
        orderType: OrderType.ASC_OR_SMALLER,
        uriType: UriType.EXTERNAL,
        ignoreCase: true,
      );

Exception

 E  Failed to handle method call
                                                                                                    kotlin.UninitializedPropertyAccessException: lateinit property context has not been initialized
                                                                                                    	at com.lucasjosino.on_audio_query.PluginProvider.context(PluginProvider.kt:63)
                                                                                                    	at com.lucasjosino.on_audio_query.controllers.PermissionController.permissionStatus(PermissionController.kt:41)
                                                                                                    	at com.lucasjosino.on_audio_query.OnAudioQueryPlugin.onMethodCall(OnAudioQueryPlugin.kt:79)
                                                                                                    	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
                                                                                                    	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
                                                                                                    	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
                                                                                                    	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:938)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:201)
                                                                                                    	at android.os.Looper.loop(Looper.java:288)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:7839)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
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

1 participant