应用关闭时接收通知 [英] Receive notification when app is closed
本文介绍了应用关闭时接收通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试实现系统以在我的应用程序上接收推送通知。
我使用Firebase,当应用程序处于活动状态或在后台运行时,一切正常,但是在关闭应用程序时没有任何反应。
我试图创建一个 WakefullBroadcastReceiver
:
I try to implement system to receive push notifications on my application.
I use Firebase and everything is ok when the app is active or in background but nothing happen when the app is closed.
I tried to create a WakefullBroadcastReceiver
like that :
public class NotificationReceiver extends WakefulBroadcastReceiver {
public static final String action = "com.myapp.notification.RECEIVE";
private static final String KEY_PUSH_DATA = "com.parse.Data";
@Override
public void onReceive(Context context, Intent intent) {
String intentAction = intent.getAction();
switch (intentAction) {
case action:
String pushDataStr = intent.getStringExtra(KEY_PUSH_DATA);
if (pushDataStr == null) {
return;
}
Log.e("PUSH", "Push data : "+pushDataStr);
Bundle extras = intent.getExtras();
MyappNotificationManager.getInstance().parseBundle(extras);
break;
}
}
}
我在 Manifest.xml
<receiver android:name=".notification.NotificationReceiver">
<intent-filter>
<action android:name="com.myapp.notification.RECEIVE"/>
</intent-filter>
</receiver>
它不起作用,我无法在Android开发者网站上找到文档。
It doesn't work and I can't find documentation on Android developper website.
感谢您的帮助。
推荐答案
添加到Manifest.xml中:
add to Manifest.xml :
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application>
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
</application>
这篇关于应用关闭时接收通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文