Android 如何防止传入OneSignal通知的警报?

Android 如何防止传入OneSignal通知的警报?,android,push-notification,onesignal,Android,Push Notification,Onesignal,我使用单信号推送通知。当android应用程序位于前台并收到通知时,它会创建一个带有通知的警报框。如何防止在接收通知时出现这种情况?来自SDK-当您启动OneSignal时,请确保使用“无”调用inFocusDisplaying以禁用OneSignal的应用程序内AlertBox 同样在NotificationReceivedHandler部分- 重要行为说明- 如果您将在应用程序中显示自己的 消息收到通知时,请确保呼叫 inFocusDisplaying with None可禁用OneSign

我使用单信号推送通知。当android应用程序位于前台并收到通知时,它会创建一个带有通知的警报框。如何防止在接收通知时出现这种情况?

来自SDK-当您启动OneSignal时,请确保使用“无”调用inFocusDisplaying以禁用OneSignal的应用程序内AlertBox

同样在NotificationReceivedHandler部分-

重要行为说明- 如果您将在应用程序中显示自己的 消息收到通知时,请确保呼叫 inFocusDisplaying with None可禁用OneSignal的应用程序内AlertBox


我有类似的问题,我通过使用

下面是如何在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);
        }*/

        }
    });
}
}

使用此代码行,我解决了我的问题

OneSignal.inFocusDisplaying(2);

只需在windows.plugin.signal中添加这一行

.inFocusDisplaying(window.plugins.OneSignal.OSInFocusDisplayOption.Notification)
例如:-

window.plugins.OneSignal
.startInit("YOUR_APPID")
.inFocusDisplaying(window.plugins.OneSignal.OSInFocusDisplayOption.Notification)
.endInit();

在OneSignal 4.0中进行了更改

对于Kotlin:

OneSignal.setNotificationWillShowInForegroundHandler { notificationReceivedEvent ->
    notificationReceivedEvent.complete(null)
}
对于Java:

OneSignal.setNotificationWillShowInForegroundHandler(new NotificationWillShowInForegroundHandler() {
  @Override
  void notificationWillShowInForeground(OSNotificationReceivedEvent notificationReceivedEvent) {    
     notificationReceivedEvent.complete(null);
  }
});

接收器是否在活动中实现?如果是的话,那可能就是问题所在。尝试将receiver设置为一个单独的类。这里有一个关于ios的类似问题,因此我认为可以通过禁用某些选项来解决,因为默认情况下它会创建警报。