3

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

按照指南,我也能够向 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);
4

2 回答 2

0

我已经通过安装以下版本来修复它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
        })
}
于 2016-11-04T06:52:14.377 回答
0
  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',
                },

于 2021-10-01T13:18:00.103 回答