Android 对通知不响应本机推送通知';t触发器

Android 对通知不响应本机推送通知';t触发器,android,react-native,react-native-push,Android,React Native,React Native Push,我正在使用zo0r库 每次打开应用程序时都会运行此代码: PushNotification.configure({ onNotification: function(notification) { console.log('onNotification'); ToastAndroid.show('onNotification', 3000); } }); 我从后台服务发送本地推送通知: PushNotification.localNotifica

我正在使用zo0r库

每次打开应用程序时都会运行此代码:

PushNotification.configure({
    onNotification: function(notification) {
        console.log('onNotification');
        ToastAndroid.show('onNotification', 3000);
    }
});
我从后台服务发送本地推送通知:

PushNotification.localNotification({
    message: 'Hello World',
    smallIcon: 'ic_launcher'
});
通知已送达。当我单击它时,
onNotification
方法不会被调用,然后当我收到另一个通知时,它实际上会被调用。似乎只有当应用程序是内存atm时,它才能工作

我做错什么了吗


我还打开了一个GitHub。

在我的代码中,我在
App
类之外配置了通知-这是一个问题。我刚刚将配置移动到App constructor,现在它工作正常,调用onNotification没有问题:

class App extends React.Component {
    constructor(props) {
        super(props);
        PushNotification.configure({ ... });
    }
}

最新的
react-native-push-notification
lib版本建议如下:

它专门编写为不将配置置于react生命周期中。否则Android就不会有正确的行为(这一点让我非常痛苦!)。 这里有一个很好的教程: 解释得不好,但方法是完美的。使用类来初始化和调用方法。按照他的建议在顶部组件中初始化类。它工作得很好。 使用本教程完成缺少的信息:
祝你好运

在我的案例中,我遵循了文档中的所有内容,包括android的React生命周期内容,但以下更改除外,其中我没有配置正确的意图过滤器操作,即

<action android:name="com.google.firebase.MESSAGING_EVENT" />

做下面的更改,这应该会起作用

<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService" android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

以前我使用这个动作是因为侦听器没有触发

<action android:name="com.google.android.c2dm.intent.RECEIVE" />

它的常见问题是,使用启动屏幕时会出现此问题。 按如下方式编辑清单:

<activity
            android:name=".SplashActivity"
            android:theme="@style/SplashTheme"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize" >
          <intent-filter>
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.INFO" />
          </intent-filter>
        </activity>


hi,@andrei你得到设备令牌了吗?@andrei我想在登录到应用程序内部后调用onNotification,所以我创建了一个主组件,在其中调用了这个内部构造函数,但这个函数在从fcm发送测试消息时没有响应?有什么想法吗?@ArchanaSharma我认为对于最新版本,它必须在所有组件之外,所以它被称为100%,而不是其他任何东西。请参阅用法部分:我已经在组件生命周期之外(在App.js主文件的构造函数中)使用了它,我的问题是每次收到通知时,它是否会自动收到?因为在这里,我的App.js在应用程序启动时调用过一次,在从fcm发送测试消息时,控制台内部的onNotification不起作用。你解决了问题了吗?我尝试了相同的方法,但PushNotification.localNotification没有触发,即使我尝试按下按钮来触发该功能?你是否可以工作?我也遇到同样的问题
<activity
            android:name=".SplashActivity"
            android:theme="@style/SplashTheme"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize" >
          <intent-filter>
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.INFO" />
          </intent-filter>
        </activity>