首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >react本机-推送通知-本地通知不适用于Android。

react本机-推送通知-本地通知不适用于Android。
EN

Stack Overflow用户
提问于 2021-02-21 04:36:23
回答 1查看 10.4K关注 0票数 6

有人能告诉我我哪里出了问题吗?从使用说明....theres上可以看到,如果您只使用本地通知,并且使用autolinking....except将googlePlayServicesVersion = "<Your play services version>" // default: "+"添加到android/build.gradle....and <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> + <uses-permission android:name="android.permission.VIBRATE" /> to AndroidManifest.xml,则不需要对Android特定的文件进行任何修改。

下面是我的主要源代码

代码语言:javascript
运行
复制
PushNotification.configure({
  // (optional) Called when Token is generated (iOS and Android)
  onRegister: function(token) {
    console.log('onRegister token:', token);
  },

  // (required) Called when a remote is received or opened, or local notification is opened
  onNotification: function(notification) {
    console.log('onNotification:', notification);
    notification.finish(PushNotificationIOS.FetchResult.NoData);
  },

  // Should the initial notification be popped automatically
  popInitialNotification: true,
  requestPermissions: true,
});

  userNowInactive = () => {
          this.showNotification();
 }

  showNotification = () => {
    PushNotification.localNotification({
      //ios and android properties
      title: 'Face2Face: Beacon Timer Expired',
      message: 'Perhaps set your beacon timer for another hour?',
      playSound: true,
      soundName: 'sound.mp3',
      //android only properties
      channelId: 'your-channel-id',
      autoCancel: true,
      // largeIcon: 'ic_launcher',
      // smallIcon: 'ic_launcher',
      bigText: 'Face2Face: Beacon Timer Expired',
      subText: 'Perhaps set your beacon timer for another hour?',
      vibrate: true,
      vibration: 300,
      priority: 'high',
      //ios only properties...is there any?
    });
  };
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-23 22:31:49

你创造了频道吗?似乎你需要创造一个才能让它发挥作用。

https://github.com/zo0r/react-native-push-notification#channel-management-android

若要使用通道,请在启动时创建它们,并将匹配的channelId传递到PushNotification.localNotification或PushNotification.localNotificationSchedule。

代码语言:javascript
运行
复制
PushNotification.createChannel(
    {
      channelId: "channel-id", // (required)
      channelName: "My channel", // (required)
      channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
      playSound: false, // (optional) default: true
      soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
      importance: 4, // (optional) default: 4. Int value of the Android notification importance
      vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
    },
    (created) => console.log(`createChannel returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
  );
票数 21
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66299182

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档