首页 > 解决方案 > 应用程序被杀死时Android中的FCM通知

问题描述

我正在尝试使用此链接将推送通知(FCM)发送到我的 android 应用程序。当应用程序在后台时一切正常,但是一旦我终止应用程序,我就不会收到任何通知。我使用 Lenovo Tab 和 Android 7.1 OS.I还尝试签署应用程序并安装为 APK。下面是我的 gradle 文件和 logcat 输出:-

        <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/plain" />
        </intent-filter>
    </activity>
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

    <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
        android:value="YOUR NOTIFICATION CHANNEL NAME"/>
    <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
        android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/>
    <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
        android:resource="@android:color/white"/>
    <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.liappmanager" />
        </intent-filter>
    </receiver>

    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
    <service
        android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>
    <service
        android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <service android:name=".MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>

    <service android:name=".FirebaseIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>

</application>

logcat 输出:-

03-02 12:00:15.673  1489  1536 W BroadcastQueue: Unable to launch app 
com.liappmanager/10279 for broadcast Intent { 
act=com.google.android.c2dm.intent.RECEIVE flg=0x10000010 
pkg=com.liappmanager (has extras) }: process is not granted
03-02 12:00:15.676  2369  2369 W GCM     : broadcast intent callback: 
result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE 
flg=0x10000000 pkg=com.liappmanager (has extras) }

正如您从 logcat 中看到的那样,我了解未授予权限,但我在 gradle 文件中添加了权限。我仍然缺少有关权限的内容。

[已解决]:如果您使用联想,我终于解决了只需转到设置->电池优化->所有应用程序->{您的应用程序}->不要优化(检查它)就是这样(重新启动设备),将解决问题以供进一步参考检查

标签: androidpush-notification

解决方案


推荐阅读