[英]NotificationCompat.Builder shows a Dialog instead of notification
我在聊天应用程序中使用OneSignal的推送通知。
如果用户在应用程序中,而不在对话活动中,则当收到通知时,将绘制一个对话框,而不是通知。
我想显示一个通知,而不是一个对话框。 这是代码:
protected boolean onNotificationProcessing(OSNotificationReceivedResult notification) {
almacen=((Almacen)getApplication());
JSONObject noti=notification.payload.additionalData;
try {
idChat=noti.getInt("idchat");
} catch (JSONException e) {
e.printStackTrace();
}
showNoti=!(almacen.getIdChat()==idChat);
if(showNoti){
OverrideSettings overrideSettings = new OverrideSettings();
overrideSettings.extender = new NotificationCompat.Extender() {
@Override
public NotificationCompat.Builder extend(NotificationCompat.Builder builder) {
Bitmap icon = BitmapFactory.decodeResource(Almacen.getContext().getResources(),
R.drawable.chat);
builder.setLargeIcon(icon);
return builder.setColor(new BigInteger("FF0000FF", 16).intValue());
}
};
OSNotificationDisplayedResult displayedResult = displayNotification(overrideSettings);
Log.d("OneSignalExample", "Notification displayed with id: " + displayedResult.androidNotificationId);
}else{
if(almacen.getActivity()!=null){
almacen.getActivity().reload();
}
}
return true;
}
使用此功能,应用程序的行为类似于说的:显示一个对话框,而不是通知。
如何避免这种情况,而是显示通知而不是对话框?
谢谢。
通过添加以下行,我已经解决了它:
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
在startInit方法中:
OneSignal.startInit(this)
.setNotificationOpenedHandler(new MyNotificationOpenedHandler())
.setNotificationReceivedHandler(new MyNotificationReceivedHandler())
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.init();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.