Firebase 带有FCM推送通知的ionic 3在Android设备上不起作用

Firebase 带有FCM推送通知的ionic 3在Android设备上不起作用,firebase,firebase-cloud-messaging,ionic3,cordova-plugin-fcm,Firebase,Firebase Cloud Messaging,Ionic3,Cordova Plugin Fcm,我一直在尝试从PostMan或CURL PHP脚本向我的Android设备发送推送通知,但我没有收到消息。如果我从Firebase控制台发送通知,通知生效,我就会收到推送通知。以下是我在app.component.ts上的代码: import { Component, ViewChild } from '@angular/core'; import { Nav, Platform, AlertController } from 'ionic-angular'; import { HomePage

我一直在尝试从PostMan或CURL PHP脚本向我的Android设备发送推送通知,但我没有收到消息。如果我从Firebase控制台发送通知,通知生效,我就会收到推送通知。以下是我在app.component.ts上的代码:

import { Component, ViewChild } from '@angular/core';
import { Nav, Platform, AlertController } from 'ionic-angular';
import { HomePage } from '../pages/home/home';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import {FCM, NotificationData} from "@ionic-native/fcm";
@Component({
  templateUrl: 'app.html',
  providers: [Services]
})
export class MyApp {
 @ViewChild(Nav) nav: Nav;
 rootPage:any;
 pages: Array<{title: string, component: any, icono: any}>;

 constructor(public platform: Platform, public alertCtrl: 
 AlertController, public statusBar: StatusBar, public splashScreen: 
 SplashScreen, private fcm: FCM ) {
  this.initializeApp();

  }

 initializeApp() {
 this.platform.ready().then(() => {
  this.statusBar.styleDefault();
  this.splashScreen.hide();

   this.fcm.getToken()
    .then((token:string)=>{
     console.log("The token to use is: ",token);
    })
    .catch(error=>{
      console.error(error);
    });


  this.fcm.onTokenRefresh().subscribe(
    (token:string)=>console.log("Nuevo token",token),
    error=>console.error(error)
  );


  this.fcm.onNotification().subscribe(
    (data:NotificationData)=>{
      if(data.wasTapped){
        console.log("Received in background",JSON.stringify(data));
      }else{

        console.log("Received in foreground",JSON.stringify(data))
      }
     },error=>{
      console.error("Error in notification",error)
     }
  );

});
从'@angular/core'导入{Component,ViewChild};
从“ionic angular”导入{Nav、平台、AlertController};
从“../pages/home/home”导入{HomePage};
从'@ionic native/status bar'导入{StatusBar};
从'@ionic native/SplashScreen'导入{SplashScreen};
从“@ionic native/FCM”导入{FCM,NotificationData}”;
@组成部分({
templateUrl:'app.html',
供应商:[服务]
})
导出类MyApp{
@ViewChild(导航)导航:导航;
根页面:任何;
页面:数组;
构造函数(公共平台:平台,公共警报Ctrl:
AlertController,公共状态栏:状态栏,公共屏幕:
SplashScreen,专用fcm:fcm){
这是.initializeApp();
}
初始化EAPP(){
this.platform.ready()。然后(()=>{
this.statusBar.styleDefault();
这个.splashScreen.hide();
this.fcm.getToken()
.然后((令牌:字符串)=>{
log(“要使用的令牌是:”,令牌);
})
.catch(错误=>{
控制台错误(error);
});
此.fcm.onTokenRefresh().subscribe(
(token:string)=>console.log(“Nuevo token”,token),
error=>console.error(错误)
);
此.fcm.onNotification().subscribe(
(数据:NotificationData)=>{
如果(data.wasTapped){
log(“在后台接收”,JSON.stringify(数据));
}否则{
log(“前台接收”,JSON.stringify(数据))
}
},错误=>{
console.error(“通知中的错误”,error)
}
);
});
这是我的邮递员帖子:标题:

这是我的留言:

以下是回应:

正如您所看到的,我收到了一个成功消息:1->这意味着通知已发送,但在我的Android设备中从未收到

有人有同样的问题吗? 正如我之前所说,我从firebase控制台收到通知。 在advanced中,感谢您的评论。

尝试以下有效负载:

 {
    "notification":{
      "title":"Title1", 
      "body": "Body1",  
      "sound": "default"
    },
    "data":{
      "param1":"param1",  
      "param2": "param2"
    },
    "to":"*Token*", 
    "priority":"high"
  }

请尝试这个作为背景

 {
   data: {
        title: title,
        body: body,
        "sound": "default",
        "content-available": "1",
        "click_action": "FCM_PLUGIN_ACTIVITY"
    },
    tokens: Tokens
}
或者,您可以尝试使用前台数据和通知键

{
   notification: {
        title: title,
        body: body,
        "sound": "default",
        "content-available": "1",
        "click_action": "FCM_PLUGIN_ACTIVITY"
    },
    tokens: Tokens
}

您好CaribeSoft,您解决了这个问题吗,我得到了相同的问题Hi Audit,还没有解决。我已经解决了。实际上我没有尝试postman…直接编写PHP代码,它可以工作。您可以发布您的代码吗?