简体   繁体   English

如何在应用前台制作信号推送通知警报

[英]How to make onesignal push-notification alert in app foreground

I want my OneSignal push-notification to alert in foreground. 我希望我的OneSignal推送通知在前台发出警报。 I want notification to alert when the app is not running in phone's background. 当应用未在手机背景中运行时,我希望通知提醒。 I already have my background alert working. 我的背景警报已经完成了。

OneSignal.startInit(this)
                .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
                .unsubscribeWhenNotificationsAreDisabled(true)
                .init();

I expect the app to notify phones even when the app is not running in background. 我希望即使应用程序没有在后台运行,该应用程序也会通知手机。 (That s foreground notification ) (那是前景通知)

Create a class named application class 创建一个名为application class的类

public class ApplicationClass extends MultiDexApplication {
    @Override
    public void onCreate() {
        super.onCreate();
        OneSignal.startInit(this)
                .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
                .unsubscribeWhenNotificationsAreDisabled(true).setNotificationOpenedHandler(new NotificationOpenHandler(this))
                .init();




    }
    @Override
    protected void attachBaseContext(Context context) {
        super.attachBaseContext(context);
        MultiDex.install(this);
    }

and add this class to manifest like below 并将此类添加到如下所示的清单中

<application
        android:name=".ApplicationClass"
        android:allowBackup="true"
        android:fullBackupContent="false"
        android:icon="@mipmap/ic_icon_updated"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 OneSignal 从静默推送通知中获取消息? - How to get a message from a silent Push notification with OneSignal? 推送通知的前景和背景 - Push notification foreground and background 我的应用未运行时,如何发送类似Facebook的推送通知(背景/前景) - how can i send push notification like facebook while my app is not running(background/foreground) 如何获取通知onesignal的内容并将其显示在我的Android应用程序中 - How to get content of notification onesignal and show it in my android app 如何实现 OneSignal 推送通知到 java(不是 javascript)后端 web 应用程序 - How can I implement OneSignal push notification to java (not javascript) backend web application 如何在java中进行小型警报通知 - How to make small alert notification in java OneSignal:收到通知时Android应用程序崩溃 - OneSignal: Android app craches when notification received 是否可以通过POSTMAN向特定的应用程序包名称发送FCM推送通知? - Is it possible to send FCM push-notification to the particular application package name through POSTMAN? 当用户点击推送通知消息时,我的应用程序启动。 如何使应用程序完整显示推送消息? - When user taps on the push notification message, my app launches. How to make the app display the push message in full? 如果应用程序在前台,通知不会显示在通知抽屉中 - Notification is not displayed in notification drawer if app is in foreground
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM