Node.js-Flutter-FCM :i'm not receiving Push notifications

Viewed 23
async function sendNotif( title, body0,token){

return await admin.messaging().sendMulticast({
tokens: [token],//"dHUKMkIxRbS3uIpdnA1Qef:APA91bHQd2XUpFyWzfdbKrpPV2T9b0uJx9TfKZcyF-O_oAbQ13yA5R-52t_RTb_QSPrMpxw1OV9z8sNFRth5wGuCAld_9VsKr4oRdSWsMzqhrbKcTLC2rAp5QLOUALqiTadyvyvcjTmb!",
notification:{
  title : title,
  body:body0},
data: {
  title: "This is a firebase message",
  message: "expo-notifications should be triggered",
  "hello": "world",
  click_action:"FLUTTER_NOTIFICATION_CLICK"
},
// Set Android priority to "high"
android: {
  priority: "high",
},
// Add APNS (Apple) config
apns: {
  payload: {
    
    aps: {
      "contentAvailable": true,
    },
  },
  headers: {
    
    "apns-push-type": "background",                                     
    "apns-priority": "5", // Must be `5` when `contentAvailable` is set to true.
      "apns-topic": "io.flutter.plugins.firebase.messaging", // bundle identifier
  
   },}
});

}

this is my AndroidManifest.xml

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.untitled">
<uses-permission android:name="android.permission.INTERNET"/>
<application
    android:label="untitled"
    android:name="${applicationName}"
    android:icon="@mipmap/ic_launcher">
    <activity
        android:name=".MainActivity"
        android:exported="true"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
        <!-- Specifies an Android theme to apply to this Activity as soon as
             the Android process has started. This theme is visible to the user
             while the Flutter UI initializes. After that, this theme continues
             to determine the Window background behind the Flutter UI. -->
        <meta-data
          android:name="io.flutter.embedding.android.NormalTheme"
          android:resource="@style/NormalTheme"
          />
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <!-- Don't delete the meta-data below.
         This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />
</application>
and this is my flutter code i've installed all needed packages and imported it (local_notification and firebase_messaging)
FirebaseMessaging _fcm = FirebaseMessaging.instance;
Future<void> permi() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var username = prefs.getString("username");
_fcm.getToken().then((value) => prefs.setString("fireToken", "$value!"));
print(_fcm.getToken());
var fireToken = prefs.getString("fireToken");
var token = prefs.getString("token");
await http
    .post(Uri.parse("http://192.168.0.111:3000/notiftoken"),
    headers:{"Content-Type": "application/json",
          "authorization": "$token"},
        body: jsonEncode({"username": username,"token": fireToken}),
        )
    .then((value) => value)
    .catchError((e) => print(e));

 }

Future checkprm()async{
NotificationSettings settings = 
await _fcm.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);

NotificationSettings set = await _fcm.getNotificationSettings();
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
print('User granted permission');
} else if (settings.authorizationStatus == AuthorizationStatus.provisional) {
print('User granted provisional permission');
} else {
print('User declined or has not accepted permission');

} }

@override
void initState(){
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
_fcm.getToken().then((value) => print("$value"));
checkprm();
permi();
connect();
super.initState();
WidgetsBinding.instance.addObserver(this);
}

i'm trying to fix the issue for a week, but i'm still not getting results, i had some issues in manifest so i took a new one from a new flutter project i've sent a test_notification with the help of FCM, i don't know if the problem is coming from node or flutter.

if anyone know how to resolve this please share it with us

0 Answers
Related