我在 android 上实现了 onesignal 应用程序。它工作正常。但我想从网络向所有具有自定义数据的用户发送通知,我希望用户在栏上看不到任何通知。当然,当通知到来时,我会在后台做一些事情。
我怎样才能做到这一点?
提前致谢
OneSignal.startInit(this)
.setNotificationReceivedHandler(new NotificationReceivedHandler())
.setNotificationOpenedHandler(new NotificationOpenedHandler())
.init();
OneSignal.setSubscription(true);
我在这里做点什么
class NotificationReceivedHandler implements OneSignal.NotificationReceivedHandler {
@Override
public void notificationReceived(OSNotification notification) {
JSONObject data = notification.payload.additionalData;
String customKey;
if (data != null) {
customKey = data.optString("custom", null);
if (customKey != null)
{
//I do sth here
}
}
}
}
你能检查一下下面的代码片段吗?
class NotificationReceivedHandler implements OneSignal.NotificationReceivedHandler {
@Override
public void notificationReceived(OSNotification notification) {
JSONObject data = notification.payload.additionalData;
String customKey;
if (data != null) {
customKey = data.optString("custom", null);
if (customKey != null)
{
//I do sth here
NotificationManager nMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nMgr.cancelAll();
}
}
}
}
如果这里仍然面临问题发布问题:https : //github.com/OneSignal/OneSignal-Android-SDK/issues
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句