Я использую Firebase Messaging в качестве плагина уведомлений Firebase в флаттере для отправки и получения уведомлений. Но когда я запускаю уведомление с одного телефона на другой, оно срабатывает, но уведомление не извлекается на другом телефоне, когда приложение находится в фоновом режиме. И OnMessage не получает никаких уведомлений на другие телефоны. Я не могу понять, почему это происходит когда-то, а не каждый раз, когда я здесь, поставив здесь свой код уведомлений, чтобы вы поняли, как я это сделал
import 'dart:convert';
import 'dart:io';
import 'package:device_info/device_info.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:mangoo/ui/Calls/VideoCall/calls.dart';
import 'package:mangoo/ui/Calls/VoiceCall/voice_call.dart';
class FirebaseNotifications {
FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
// FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
BuildContext context;
void setUpFirebase(BuildContext context) {
print("in Firebase Setup");
// _firebaseMessaging = FirebaseMessaging();
this.context = context;
// flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
// firebaseCloudMessaging_Listeners();
initNotification();
}
initNotification() {
print("initNotification ")
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('on messagemessage ${message}');
if (message.containsKey('data')) {
String channel_name = message['data']['channel_name'];
String phoneNumber = message['data']['phone_number'];
String screen_id = message['data']['screen_id'];
if (screen_id == "0") {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CallPage(
channelName: channel_name,
phoneNumber: phoneNumber,
),
),
);
} else if (screen_id == "1") {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VoiceCallPage(
channelName: channel_name,
phoneNumber: phoneNumber,
),
),
);
}
}
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
// displayNotification(message);
// Navigator.push(
// context, MaterialPageRoute(builder: (context) => CallPage()));
// _showItemDialog(message);
},
onBackgroundMessage: myBackgroundMessageHandler,
// print('on backgroundmessage ${message}');
// },
onResume: (Map<String, dynamic> message) async {
print('on messageResume ${message}');
// displayNotification(message);
},
onLaunch: (Map<String, dynamic> message) async {
print('on messageLaunch ${message}');
// displayNotification(message);
},
);
}
Widget ShowDialog(String channelName, String phoneNumber) {
return Container(
width: MediaQuery.of(context).size.width / 2,
height: MediaQuery.of(context).size.height / 4,
child: Column(
children: <Widget>[
Container(
color: Colors.yellowAccent,
width: MediaQuery.of(context).size.width,
height: 50,
child: Text("Incoming Video call")),
SizedBox(
height: 5.0,
),
Container(
child: Row(
children: <Widget>[
RaisedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CallPage(
channelName: channelName,
phoneNumber: phoneNumber,
),
),
);
},
// textColor: Colors.black,
child: Text(
"ACCEPT",
style: TextStyle(color: Colors.black, fontSize: 12),
),
),
VerticalDivider(
width: 3,
),
RaisedButton(
onPressed: () {},
color: Colors.green,
child: Text(
"REJECT",
style: TextStyle(color: Colors.black, fontSize: 12),
),
)
],
),
)
],
));
}
}