【问题标题】:React native show ICON only not full image仅反应原生显示图标而不是完整图像
【发布时间】:2019-09-06 13:05:26
【问题描述】:

我正在尝试实现通知,它工作正常只面临一个问题,当我只想显示带有数据的图标时,它将显示为图像。

我使用的库是react-native-push-notification

例如,我想这样显示,但单击箭头按钮时也会显示大图。

现在是这样的

这就是我想要的。

这是我的 AndroidManifest.xml

 <!-- Change the resource name to your App's accent color - or any other color you want -->
        <meta-data   android:name="com.google.firebase.messaging.default_notification_icon"
                    android:resource="@mipmap/ic_notification"/>  
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                    android:resource="@android:color/white"/>

在服务器端

$notification = array('content-available' => true, 'mutable-content' => true, 'title' => $title, 'text' => $body, 'icon' => $icon, '声音' => '默认', '徽章' => '1');

如果我通过图标,那么如果我使用图像然后图标显示但也使用大图像,则不会显示任何内容。

我的代码如下

import PushNotification from "react-native-push-notification";
import { PushNotificationIOS } from "react-native";
import { NavigationActions, StackActions } from "react-navigation";
import {ToastAndroid} from 'react-native';
const localNotification = data => {
  console.log("const localNotification" + JSON.stringify(data));
  if (data) PushNotification.localNotification(data);
  return null;
};
let getToken;

const setToken = token => (getToken = token.token);

const configure = () => {
  PushNotification.configure({
    onRegister: setToken,
    // largeIcon: "https://stag2.com/uploads/qr/407xg1.png",
    // smallIcon: "ic_notification",
    // ongoing: true,
    onNotification(notification) {
      onNotification(notification);
    }, 
    senderID: "5545454654654654",
  //  SmallIcon:"ic_notification",
    permissions: {
      alert: true,
      badge: true,
      sound: true
    },

    popInitialNotification: true,
    requestPermissions: true
  });
};
let onNotification = (notification) => {
  notification.android.setSmallIcon('ic_notification')
  // if (!!notification.title && !!notification.body) {
    // PushNotification.localNotification({
    //   title: notification.title,
    //   message:"urfusion",
    // });
  // }
};
export { configure, localNotification, getToken };

如果我推送本地通知,当应用程序在通知点击事件上打开时调用,但我想要远程推送通知而不是本地通知,我得到了我想要的。

let onNotification = (notification) => {
  notification.android.setSmallIcon('ic_notification')
  // if (!!notification.title && !!notification.body) {
     PushNotification.localNotification({
       title: notification.title,
       message:"urfusion",
     });
   }
};

【问题讨论】:

  • 您找到解决问题的方法了吗?我也遇到了同样的问题,找不到解决办法
  • 没有,我当时也是这样发布的。

标签: android react-native push-notification notifications


【解决方案1】:

图标需要带有透明背景。你可以在这里阅读更多 : read more

另一方面,对于通知,您需要为不同版本的 android 使用不同的图标。你可以在这里阅读更多 : read more

【讨论】:

  • 我已经在AndroidManifest.xml中添加了icon属性
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-12-09
  • 1970-01-01
  • 2023-03-25
  • 2012-04-29
  • 1970-01-01
  • 2020-06-27
  • 2022-07-05
相关资源
最近更新 更多