【发布时间】:2018-07-18 15:23:30
【问题描述】:
所以这个问题是不言自明的。我想知道单击的通知是分组的还是单个通知。在此基础上,将启动一个 Activity。
例如,如果通知被分组,我想启动“所有消息”活动,如果没有,它会简单地启动聊天活动。
这是我当前代码的样子:
public class NotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
private Application application;
String message;
public NotificationOpenedHandler(Application application) {
this.application = application;
}
@Override
public void notificationOpened(OSNotificationOpenResult result) {
// Get custom data from notification
JSONObject data = result.notification.payload.additionalData;
message = data.optString("message");
startApp(message);
}
private void startApp(String text) {
Intent intent;
SharedPreferences sharedPreferences = application.getSharedPreferences("appdata", Context.MODE_PRIVATE);
if (sharedPreferences.getInt("pending_notifications", 1) > 1) {
intent = new Intent(application, DemoActivity.class);
} else {
intent = new Intent(application, ReadLetterActivity.class);
}
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt("pending_notifications", 0);
editor.apply();
intent.putExtra("message", text);
startActivity(intent);
}
}
如您所见,我尝试使用 SharedPreferences,但没有达到标准。
结束,我想知道是否有办法(本机或 OneSignal 提供)知道通知是否已分组。谢谢。
【问题讨论】:
-
据我所知,通知何时被分组...如果我点击它,通知将打开以查看组中的通知。我知道 onesignal 有一个 android_group 选项,我很确定他们提供了一种方法来知道有多少通知给用户......你可以使用这个 int。
标签: android push-notification notifications onesignal