【问题标题】:PushSharp Google Cloud Messaging Heads-up notificationPushSharp Google Cloud 消息提醒通知
【发布时间】:2016-08-19 17:46:21
【问题描述】:

我正在开发适用于 Android 和 iOS 的应用程序,并且我正在使用 PushSharp(在服务器端)向这两个平台发送推送通知。特别是我正在使用(对于 Android)Firebase 平台 (FCM)。

按照this 指南,我也能够向 Android 设备设置图标和声音发送推送通知,但我认为存在问题。 当通知到达时,它不会显示为 Heads-up 通知,而仅显示为状态栏通知。

明确地说,我会:

但我只看到状态栏上显示的应用程序图标。

我如何告诉 FCM 将我的通知显示为平视通知,类似于我使用以下代码获得的通知?

NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.ic_media_play)
                        .setContentTitle("My notification")
                        .setContentText("Hello World!")
                        .setDefaults(Notification.DEFAULT_ALL)
                        .setPriority(Notification.PRIORITY_HIGH);

【问题讨论】:

  • 您找到解决方案了吗?我也有同样的问题
  • 我也遇到了同样的问题。当应用程序在前台时,我能够生成提示通知,但在应用程序在后台或死机时不能。我得到的只是系统托盘通知
  • @Carlos 我还没有找到解决方案:(
  • @Carlos 运气好吗?
  • @AmilcarAndrade:新版推送通知即使应用被杀也能正常工作。所以每当我收到远程通知时我在做什么。我在 onNotification 事件中显示本地通知

标签: android push-notification notifications firebase-cloud-messaging heads-up-notifications


【解决方案1】:

我已通过安装以下版本的react-native-push-notification 修复它

npm install zo0r/react-native-push-notification.git

在你的index.android.js

function init(){
    PushNotification.configure({
        onNotification:async (notification)=>{
                if(!notification.userInteraction && !notification.foreground){
                    PushNotification.localNotification({
                      message: "you message"
                    });
                  }
               ,
                requestPermissions:true,
                senderID:"31************",
                popInitialNotification:false
        })
}

【讨论】:

  • 我说的是 Android 原生应用;)
【解决方案2】:
  1. 您必须在 MainActivity.java 中创建一个频道。
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.os.Build;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

+      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {    
+        NotificationChannel notificationChannel = new 
+        NotificationChannel("500", "MainChannel", 
+        NotificationManager.IMPORTANCE_HIGH);
+        notificationChannel.setShowBadge(true);
+        notificationChannel.setDescription("Test Notifications");
+        notificationChannel.enableVibration(true);
+        notificationChannel.enableLights(true);
+        notificationChannel.setVibrationPattern(new long[]{400, 200, 400});
+        NotificationManager manager = getSystemService(NotificationManager.class);
+         manager.createNotificationChannel(notificationChannel);
+      }
  1. 将 channelId 添加到您的服务器:node.js 示例
        await admin
            .messaging()
            .send({
                android: {
                    priority: 'high',
                    notification: {
                        sound: 'default',
                        title: 'your title',
                        body: 'your message',
                        imageUrl: 'img-uri',
                        priority: 'high', // this is importnat
                        channelId: '500', // the channelId we created in MainActivity.java
                    },
                },
                apns: {
                    payload: {
                        aps: {
                            contentAvailable: true,
                        },
                    },
                    headers: {
                        'apns-push-type': 'background',
                        'apns-priority': '5',
                        'apns-topic': '', // your app bundle identifier
                    },
                },
                topic: //topic or token,
                data: {//send a custom data here to your client},
                notification: {
                    title: 'your title',
                    body:'your message',
                    imageUrl: 'img-url',
                },

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-27
    相关资源
    最近更新 更多