Closed 065rsh closed 3 years ago
Hi @065rsh
Can you please provide your flutter doctor -v
your flutter run --verbose
and a complete reproducible minimal code sample and also include cloud function
Thank you"
OUTPUT of flutter doctor -v
[√] Flutter (Channel stable, v1.17.3, on Microsoft Windows [Version 10.0.18362.900], locale en-US)
• Flutter version 1.17.3 at C:\src\flutter
• Framework revision b041144f83 (13 days ago), 2020-06-04 09:26:11 -0700
• Engine revision ee76268252
• Dart version 2.8.4
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
• Android SDK at C:\Users\Arsh\AppData\Local\Android\sdk
• Platform android-29, build-tools 29.0.1
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
• All Android licenses accepted.
[√] Android Studio (version 3.6)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 44.0.2
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
[!] IntelliJ IDEA Community Edition (version 2017.3)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.3.4
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
• For information about installing plugins, see
https://flutter.dev/intellij-setup/#installing-the-plugins
[√] IntelliJ IDEA Ultimate Edition (version 2019.3)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.2
• Flutter plugin version 43.0.3
• Dart plugin version 193.6015.53
[√] VS Code (version 1.46.0)
• VS Code at C:\Users\Arsh\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.11.0
[√] Connected device (1 available)
• CPH1933 • 614ddc7d • android-arm64 • Android 9 (API 28)
! Doctor found issues in 1 category.
OUTPUT of flutter run --verbose
The minimal code blocks are already mentioned in the issue, I think you can reproduce the issue using that, if there is anything that needs to be added then you can mention that.
@TahaTesser How much time will this take?
yes, I have the same issue.
any solution is there?
solutions. Please
same problem.
Any solution notification if app in background facing issue with background and foreground working fine..
Please you find a solution ?
I search and found a solution, you can check my approach on my repository https://github.com/akoua/Custom_push_notification_android
I search and found a solution, you can check my approach on my repository https://github.com/akoua/Custom_push_notification_android
Can you please explain the solution?
I'm having this problem on iOS. It's working fine on Android although it never calls the onBackgroundMessageHandler
But on iOS it's working as if it was a data message and not a notification message. Which means the message is delivered to the app but only after I open the app and onMessage from .configure(...) is called.
But if the app is on the background, I get no notification.
Also, why does the tutorial says we need onBackgroundMessageHandler if the example project doesn't have it?
Hi all, I solved this.
I was able to handle data message in Foreground, Background and Terminated(Killed) App.
Github Code -- https://github.com/Stone2517/Truact-1
and I recorded the message handling in flutter and uploaded to YouTube.
Youtube Link -- https://youtu.be/tnCk_CD4mvs
as you can see in my video
firebase_message can handle data message in foreground, background and terminated(Killed) App.
notification or notification data cannot be handled by onBackgroundMessagehandler.
I got errors with Kotlin so I had to switch to java.
json data from FCM is important "data" key can be detected by background. but "notification" cannot
@Stone2517 Thank you. It was bug of plugin? I thought just JSON keys.
Ah, it is not pull-request. you knew how to resolve.
you deleted the evil key (notification
) in the timeline :>
@yourshinsuke before recording I made few tests with notification key.
I just want to show how onBackgroundMessageHandler is going to handle with and without the notification key.
Check this.
Firebase Cloud Messaging link --- https://firebase.google.com/docs/cloud-messaging/android/receive#backgrounded
when we set notification and data message in payload onBackgroundMessageHandler is not triggered when the app is backgrounded or killed.
I think the best solution would be https://pub.dev/packages/flutter_local_notifications
send the data only payload to device and onBackgroundMessageHandler will be triggered then we can create a local notification through flutter_local_notifications package.
@Stone2517 Thank you. It was bug of plugin? I thought just JSON keys.
@yourshinsuke I think its not the issue with plugin.
@Stone2517 Hello, I watched your video and project, but I can’t run the project. I feel that I have figured out your configuration, but I cannot receive notifications when the App is killed. Can you see why? My example: https://github.com/lizhuoyuan/flutter_nn_fcm
@lizhuoyuan Did you use same configuration and code. check twice, check flutter doctor everything. I'm in busy I can't check your code right now. Sorry
aaa i see, your background function doesnt work if you used this payload
"notification": { "title": "This is tittle", "body": "....", "sound": "notification.mp3", "android_channel_id" : "manyaran_id", "click_action" : "FLUTTER_NOTIFICATION_CLICK" },
if you want to use bacgkround function , try send without "notification".
@Stone2517 Hello, I watched your video and project, but I can’t run the project. I feel that I have figured out your configuration, but I cannot receive notifications when the App is killed. Can you see why? My example: https://github.com/lizhuoyuan/flutter_nn_fcm
Did you get the solution ?
@Stone2517 Hello, I watched your video and project, but I can’t run the project. I feel that I have figured out your configuration, but I cannot receive notifications when the App is killed. Can you see why? My example: https://github.com/lizhuoyuan/flutter_nn_fcm
Did you get the solution ?
Thank you for your attention, I haven't solved it before, and I am doing other things recently.
Hi all, I solved this.
I was able to handle data message in Foreground, Background and Terminated(Killed) App.
Github Code -- https://github.com/Stone2517/Truact-1
and I recorded the message handling in flutter and uploaded to YouTube.
Youtube Link -- https://youtu.be/tnCk_CD4mvs
as you can see in my video
firebase_message can handle data message in foreground, background and terminated(Killed) App.
notification or notification data cannot be handled by onBackgroundMessagehandler.
I got errors with Kotlin so I had to switch to java.
@Stone2517 I have tried with postman. It is only working in foreground and background state. But not working in app killed state.
Any suggestions to solve my problem ?
@MaheshPeri19 Did you check the config and code? Can I see your code?
@Stone2517 Hello, I watched your video and project, but I can’t run the project. I feel that I have figured out your configuration, but I cannot receive notifications when the App is killed. Can you see why? My example: https://github.com/lizhuoyuan/flutter_nn_fcm
Did you get the solution ?
I have used the new version these days to solve the problem, and it should be a network/mobile problem before. Thanks
@MaheshPeri19 please check your phone's android version
@Stone2517
I have checked your example project and implemented createChannel method in Application.java class and added necessary steps in build gradle file also. I am sending as data payload like below
{
"data": {
"sound": "default",
"title": "Push Title",
"body": "Hi Mahesh",
"chat_message_type": "
So it is working for foreground and background also. It is not working with killed state. Some time background notifcations also not coming.
@lizhuoyuan My android device version is Android 10. In my project, i am using compile and target versions are 30. minimum sdk is 23.
@Stone2517 I have checked your example project and implemented createChannel method in Application.java class and added necessary steps in build gradle file also. I am sending as data payload like below { "data": { "sound": "default", "title": "Push Title", "body": "Hi Mahesh", "chat_message_type": "" }, "to":"" }
So it is working for foreground and background also. It is not working with killed state. Some time background notifcations also not coming.
@lizhuoyuan My android device version is Android 10. In my project, i am using compile and target versions are 30. minimum sdk is 23.
For Notification you have to use notification key or it might be network issue.
When you send notification and data values when app killed onMessageReceived is not going to be triggered. For that you need to send data only message. How did you check the data only message received when app is killed ? Refer this for more : https://github.com/FirebaseExtended/flutterfire/issues/2777#issuecomment-686324396
{
"to": "..",
"notification": {
"icon": "juno_icon",
"title": "自己的土",
"body": "自己的地🤮",
"sound": "default",
"badge": 1,
"content_available": true
},
"data": {
"title": "自己的土",
"body": "自己的地",
"id": 1,
"type": 2,
"route": "ceceapp://main/fortune"
}
}
This is the content I issued. You can refer to it. In theory, there is a notification. And make sure that the Google framework is complete,
@MaheshPeri19
@Stone2517 I have checked this comment #2777 (comment). I dont want user manually click notification from notification tray. I just want user receives notification and automatically trigger some event.
So as per your #2777 comment, my payload needs both notification and data as well ? Then will it receives in killed/terminated state also ?
If i add both notification and data payloads, i am getting below error while app is in background.
Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
I already followed for adding keys in android manifest for notification channel.
Edited :
https://pub.dev/packages/firebase_messaging As per flutter firebase_messaging package, onTerminated they mentioned not supported by plugin, message is lost (screenshot below)
@MaheshPeri19 In order to show notification as well as trigger an event, you need to use data only message. When the event triggered display the notification to user by using flutter local notifications package and store the data message.
I'm able to handle data only message when the app is killed with backgroundMessageHandler
@Stone2517 Yes. I am using data only message. Your code is not working for me. Actually i am working on one to one video calling just like whatsapp or skype call. Here i am using call_keep flutter package for incoming call to notify end user. So Whenever i click on call button, sending push notification to end user and notifying with incoming call.
So here it is not working with terminated/killed state. When ever push notification come, i am triggering incoming call event. For app terminated state, i am not getting push notification, so that not activating/notify end user.
@MaheshPeri19 I can't tell you where you went wrong, without code.
Can you share the code?
@Stone2517
Please find my code here : In this, if(message['data']['chat_message_type'] == 'video_call') condition is for video calling when user receives push notification. In onResume and onLaunch methods, i am not handling for video call, bcz i dont want to user click notification manually. It needs to trigger automatically like incoming call.
// =====Firebase ====
void registerNotification() {
LoginViewModel loginViewModel =
Provider.of<LoginViewModel>(context, listen: false);
UserInfoModel userObject = loginViewModel.currentUserObject;
print(
"useerobject.userid/registerPushNotification is ${userObject.userId}");
_firebaseMessaging.configure(
//
onMessage: (Map<String, dynamic> message) {
print('onMessage : $message');
if (message['data']['chat_message_type'] == 'video_call') {
//
displayIncomingCall("Incoming Call...");
//
} else {
Platform.isAndroid
? showPushNotificationInAlertForeground(
message['notification'], message['data'])
: showPushNotificationInAlertForeground(
message['aps']['alert'], message['data']);
}
return;
},
onResume: (Map<String, dynamic> message) {
this.navigateToChatPersonScreen(
peerId: message['data'][kFirebaseUserId],
peerName: message['data'][kFirebaseUserName]);
print('onResume : $message');
return;
},
onLaunch: (Map<String, dynamic> message) {
this.navigateToChatPersonScreen(
peerId: message['data'][kFirebaseUserId],
peerName: message['data'][kFirebaseUserName]);
print('onLaunch : $message');
return;
},
onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler,
);
//_firebaseMessaging.requestNotificationPermissions();
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});
_firebaseMessaging.getToken().then((token) {
print('token ===========>: $token');
FirebaseFirestore.instance
.collection(kFirebaseUsersCollectionKey)
.doc(userObject.userId)
.update({kFirebaseUserPushToken: token});
}).catchError((err) {
print("error get token ==================> $err");
// Fluttertoast.showToast(msg: err.message.toString());
CustomToast.showErrorToastShort(toastMessage: err.message.toString());
});
}
void configLocalNotification() {
var initializationSettingsAndroid =
new AndroidInitializationSettings(appIconName);
var initializationSettingsIOS = new IOSInitializationSettings();
var initializationSettings = new InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(initializationSettings);
}
//=======
// TOP-LEVEL or STATIC function to handle background messages
static Future<dynamic> myBackgroundMessageHandler(
Map<String, dynamic> message) async {
print('AppPush myBackgroundMessageHandler : $message');
// print("=======================================");
displayIncomingCall("Incoming Call...);
if (message['data']['chat_message_type'] == 'video_call') {
//
displayIncomingCall("Incoming Call...");
}
return Future<void>.value();
}
static Future<void> displayIncomingCall(String number) async {
final String callUUID = newUUID();
print('Display incoming call now');
print('[displayIncomingCall] $callUUID number: $number');
_callKeep.displayIncomingCall(callUUID, number,
handleType: 'number', hasVideo: false);
}
// Call Keep Methods
static Future<void> answerCall(CallKeepPerformAnswerCallAction event) async {
print("answer call called........");
Map<dynamic, dynamic> pushDict = Map();
pushDict = await FirebaseHelpers.getVoiceVideoCallDocuments();
FlutterRingtonePlayer.stop();
_callKeep.backToForeground();
_callKeep.endAllCalls();
if (await Permissions.cameraAndMicrophonePermissionsGranted()) {
print("new pushDict/answer call is $pushDict");
Call call = Call.fromMap(pushDict);
print("call.recieverid/answercall is ${call.receiverId}");
print("call.recieverName/answercall is ${call.receiverName}");
NavigationService.instance.navigateToRoute(MaterialPageRoute(
builder: (context) => CallScreen(call: call),
));
}
}
Hey @065rsh, we're a few major versions past since this issue was created. I advise using the latest messaging version, and following the updated documentation for understanding what is/isn't possible particularly with iOS integration. If you still have a valid issue, I'll reopen.
I have a cloud function deployed in firebase which gets triggered whenever a document is changed and then that cloud function will send a notification to the users' device who changed it, and this is the payload:
If the application is in the background or terminated, the onBackgroundMessage of FCM should trigger and run the callback function. The function is like this:
return Future.value();
}
_showFlutterLocalNotification(String title, String message) async { var androidPlatformChannelSpecifics = AndroidNotificationDetails( "DUE_DATE_REMINDER", "Due date reminder notification", "Notification channel for task due date reminder.", );
var iosChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails( androidPlatformChannelSpecifics, iosChannelSpecifics, );
await CustomNotificationHandler().flutterLocalNotificationsPlugin.show( 0, title, message, platformChannelSpecifics, ); }
class CustomNotificationHandler { final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
Future initializeHandler() async { var initializationSettingsAndroid = AndroidInitializationSettings( "app_icon", ); var initializationSettingsIOS = IOSInitializationSettings( onDidReceiveLocalNotification: onDidReceiveLocalNotification, ); var initializationSettings = InitializationSettings( initializationSettingsAndroid, initializationSettingsIOS, );
}
Future onDidReceiveLocalNotification( int id, String title, String body, String payload) async { print("RAN onDidReceiveLocalNotification for IOS"); }
Future onSelectNotification(String payload) async { if (payload != null) { debugPrint("Notification payload: $payload"); }
} }
class Application : FlutterApplication(), PluginRegistry.PluginRegistrantCallback { override fun onCreate() { super.onCreate() FlutterFirebaseMessagingService.setPluginRegistrant(this) }
}
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="DUE_DATE_REMINDER" />