我正在尝试使用此链接将推送通知(FCM)发送到我的android应用程序。当应用程序在后台运行时一切正常,但是一旦我杀死了该应用程序,我就没有收到任何通知。我将Lenovo Tab与Android 7.1一起使用OS。我也尝试签署应用程式并安装为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文件中添加了该权限。我仍然缺少关于权限的信息。
[已解决]:如果您使用Lenovo,我终于解决了,只需转到“设置”->“电池优化”->“所有应用”->“ {YOUR APP}”->“不优化(检查)”就是这个(重新启动设备),将解决问题以进行进一步的参考检查this。