简体   繁体   English

如何在react-native中设置通知中的图像?

[英]How to set image in notification in react-native?

In Android, Native application you can easily set image in notification. 在Android,Native应用程序中,您可以轻松地在通知中设置图像。 在此输入图像描述

I need to create this functionality in my application. 我需要在我的应用程序中创建此功能。 I am using https://github.com/evollu/react-native-fcm I think, I have to create new activity for that which override notification builder. 我正在使用https://github.com/evollu/react-native-fcm我认为,我必须为覆盖通知构建器创建新活动。 but i am confuse where can i override java class using Javascript. 但我很困惑我可以在哪里使用Javascript覆盖java类。 This tutorial help me to understand how to implement image notification in native app. 本教程帮助我了解如何在本机应用程序中实现图像通知。

Thank you. 谢谢。

for image you can use picture in custom_notification using react-native-fcm package. 对于图像,您可以使用react-native-fcm包在custom_notification使用picture It should looks like: 它应该看起来像:

      const payload = {
      data: {
          snapshot: JSON.stringify(original),
          custom_notification: JSON.stringify(
{
   id: 'topics/my-notif
   title: `title`,
   body: '',
   sound: 'default',
   priority: 'high',
   icon: 'ic_launcher',
   show_in_foreground: true,
   vibrate: 300,
   action: 'android.intent.action.MAIN',
   picture: 'https://asfsgsgafasfaf',
}
          )
      }
      //,notification:{title: `Car(${original.name}) registrated`,body: 'Waiting administration approve. ' + original.description}
  };

But it is one small issue if you using Firebase storage. 但如果您使用Firebase存储,这是一个小问题。 Package overrides firebase link. 包覆盖firebase链接。 From %2F to / . %2F/ SO its a bug, I opened issue here: https://github.com/evollu/react-native-fcm/issues/931 and maybe it should be merged. 这是一个错误,我在这里打开了问题: https://github.com/evollu/react-native-fcm/issues/931https://github.com/evollu/react-native-fcm/issues/931也许应该合并。 So when you put your image from firebase storage it cannot get it and shows blank image... 因此,当您从firebase存储中放置图像时,它无法获取它并显示空白图像...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM