我使用OneSignal推送通知。当android应用程序位于前台并收到通知时,它会创建一个包含通知的警告框。如何在收到通知时阻止这种情况出现?
答案 0 :(得分:6)
来自SDK documentation - 当您启动OneInignal时,请确保使用“无”调用inFocusDisplaying以禁用应用程序AlertBox中的OneSignal。
也在NotificationReceivedHandler部分 -
重要行为说明 - 如果你将在应用程序中显示自己的 收到通知时发出消息,请务必致电 inFocusDisplaying with None禁用应用程序AlertBox中的OneSignal。
答案 1 :(得分:1)
我有类似的问题,我使用inFocusDisplaying
解决了这个问题这里是如何在android中使用它。
public class MyApplicationClass extends Application {
private static Context context;
PlayerIdsession session;
public static Context getContext() {
return context;
}
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
//MyNotificationOpenedHandler : This will be called when a notification is tapped on.
//MyNotificationReceivedHandler : This will be called when a notification is received while your app is running.
OneSignal.startInit(this)
.setNotificationOpenedHandler(new MyNotiOpenedHandler())
.setNotificationReceivedHandler( new MyNotiReceivedHandler() )
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.init();
OneSignal.idsAvailable(new OneSignal.IdsAvailableHandler() {
@Override
public void idsAvailable(String userId, String registrationId) {
if (userId != null){
session=new PlayerIdsession(context);
session.savePlayerId(userId);
Log.d("debug", "PlayerId:" + userId);
}
/* if (registrationId != null){
Log.d("debug", "registrationId:" + registrationId);
}*/
}
});
}
}
答案 2 :(得分:1)
它在 OneSignal 4.0 中发生了变化。
对于 Kotlin:
OneSignal.setNotificationWillShowInForegroundHandler { notificationReceivedEvent ->
notificationReceivedEvent.complete(null)
}
对于 Java:
OneSignal.setNotificationWillShowInForegroundHandler(new NotificationWillShowInForegroundHandler() {
@Override
void notificationWillShowInForeground(OSNotificationReceivedEvent notificationReceivedEvent) {
notificationReceivedEvent.complete(null);
}
});
答案 3 :(得分:0)
使用此代码行,我解决了我的问题。
OneSignal.inFocusDisplaying(2);
答案 4 :(得分:0)
只需在您的windows.plugin.signal中添加此行
.inFocusDisplaying(window.plugins.OneSignal.OSInFocusDisplayOption.Notification)
例如:-
window.plugins.OneSignal
.startInit("YOUR_APPID")
.inFocusDisplaying(window.plugins.OneSignal.OSInFocusDisplayOption.Notification)
.endInit();