Skip to content

Unable to answer call in background service for android ? #540

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

Open
harryandroiddev opened this issue Apr 9, 2025 · 1 comment
Open
Labels
bug Something isn't working

Comments

@harryandroiddev
Copy link

harryandroiddev commented Apr 9, 2025

Describe the bug
Unable to accept the incoming call in background service in android os .

To Reproduce
Steps to reproduce the behavior:

  1. Start background service
  2. register sip user and close the app
  3. handle sip listeners and on incoming call accept the call .

The method to answer the call throws error
mediaStream = await navigator.mediaDevices.getUserMedia(
mediaConstraints,
); // getting error at this line of code
call?.answer(
helper!.buildCallOptions(true),
mediaStream: mediaStream,
);

Error Logs

E/MethodChannel#FlutterWebRTC.Method(23398): Failed to handle method call
E/MethodChannel#FlutterWebRTC.Method(23398): java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent android.app.Activity.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter)' on a null object reference
E/MethodChannel#FlutterWebRTC.Method(23398): at com.cloudwebrtc.webrtc.video.camera.DeviceOrientationManager.start(DeviceOrientationManager.java:57)
E/MethodChannel#FlutterWebRTC.Method(23398): at com.cloudwebrtc.webrtc.video.camera.CameraUtils.(CameraUtils.java:48)
E/MethodChannel#FlutterWebRTC.Method(23398): at com.cloudwebrtc.webrtc.MethodCallHandlerImpl.initialize(MethodCallHandlerImpl.java:176)
E/MethodChannel#FlutterWebRTC.Method(23398): at com.cloudwebrtc.webrtc.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:345)
E/MethodChannel#FlutterWebRTC.Method(23398): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/MethodChannel#FlutterWebRTC.Method(23398): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/MethodChannel#FlutterWebRTC.Method(23398): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#FlutterWebRTC.Method(23398): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
E/MethodChannel#FlutterWebRTC.Method(23398): at android.os.Handler.handleCallback(Handler.java:958)
E/MethodChannel#FlutterWebRTC.Method(23398): at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#FlutterWebRTC.Method(23398): at android.os.Looper.loopOnce(Looper.java:230)
E/MethodChannel#FlutterWebRTC.Method(23398): at android.os.Looper.loop(Looper.java:319)
E/MethodChannel#FlutterWebRTC.Method(23398): at android.app.ActivityThread.main(ActivityThread.java:8893)
E/MethodChannel#FlutterWebRTC.Method(23398): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#FlutterWebRTC.Method(23398): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
E/MethodChannel#FlutterWebRTC.Method(23398): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
E/flutter (23398): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: Unable to getUserMedia: Attempt to invoke virtual method 'android.content.Intent android.app.Activity.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter)' on a null object reference
E/flutter (23398): #0 MediaDeviceNative.getUserMedia (package:flutter_webrtc/src/native/mediadevices_impl.dart:48:7)

Expected behavior
Answer the call in background

System Infomation()
[✓] Flutter (Channel stable, 3.29.2, on macOS 15.3.1 24D70 darwin-arm64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc4)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.3)
[✓] VS Code (version 1.98.2)
[✓] Connected device (5 available)
[✓] Network resources

@VictorUvarov
Copy link
Contributor

I believe the issue is because you need to call on the main thread. The SIP logic can be on the background thread, the UI and webrtc logic needs to be on the main thread. Currently both are tightly coupled in this plugin.

navigator.mediaDevices.getUserMedia(mediaConstraints)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants