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

Exception in callNumber function when called from FCM BackgroundMessage #26

Open
tanmaysathe opened this issue Sep 5, 2022 · 1 comment

Comments

@tanmaysathe
Copy link

Is it supported using callNumber function in background message?

Following is the code:


import 'dart:async';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter_phone_direct_caller/flutter_phone_direct_caller.dart';

Future<void> _messageHandler(RemoteMessage message) async {
  await Firebase.initializeApp();
  String num = message.data['number'];
  if (num.isNotEmpty) {
    await FlutterPhoneDirectCaller.callNumber(num);
  }
}
Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  FirebaseMessaging.onBackgroundMessage(_messageHandler);
  await FirebaseMessaging.instance.subscribeToTopic('demo_topic');
}

Following is the exception message:


E/MethodChannel#flutter_phone_direct_caller(28480): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter_phone_direct_caller(28480): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
E/MethodChannel#flutter_phone_direct_caller(28480): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
I/flutter (28480): FlutterFire Messaging: An error occurred in your background messaging handler:
I/flutter (28480): PlatformException(error, null, null, java.lang.NullPointerException
I/flutter (28480): 	at com.yanisalfian.flutterphonedirectcaller.FlutterPhoneDirectCallerHandler.getActivity(FlutterPhoneDirectCallerPlugin.kt:131)
I/flutter (28480): 	at com.yanisalfian.flutterphonedirectcaller.FlutterPhoneDirectCallerHandler.getPermissionStatus(FlutterPhoneDirectCallerPlugin.kt:96)
I/flutter (28480): 	at com.yanisalfian.flutterphonedirectcaller.FlutterPhoneDirectCallerHandler.onMethodCall(FlutterPhoneDirectCallerPlugin.kt:63)
I/flutter (28480): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
I/flutter (28480): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
I/flutter (28480): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319)
I/flutter (28480): 	at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
I/flutter (28480): 	at android.os.Handler.handleCallback(Handler.java:938)
I/flutter (28480): 	at android.os.Handler.dispatchMessage(Handler.java:99)
I/flutter (28480): 	at android.os.Looper.loopO
@prathmesh-jadhav
Copy link

@tanmaysathe Have you found solution?

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