在后台更新应用程序通知徽章

时间:2018-07-11 13:34:30

标签: java android firebase firebase-cloud-messaging

我正在使用Cordova Firebase插件,该插件用于发送推送通知。

在我的onMessageReceived中,我有这段代码:

Context context = this.getApplicationContext();
SharedPreferences prefs = context.getSharedPreferences("badge", Context.MODE_PRIVATE);
int count = prefs.getInt("badge", 0);
count = count + 1;
ShortcutBadger.applyCount(context, count);
SharedPreferences.Editor editor = context.getSharedPreferences("badge", Context.MODE_PRIVATE).edit();
editor.putInt("badge", count);
editor.apply();

这会增加徽章计数,但仅在我在应用程序上时才起作用。我将如何在后台或关闭应用程序的情况下运行此代码?

0 个答案:

没有答案
相关问题