0

如何将静默通知推送到 android 应用程序并在应用程序上处理它并在应用程序被杀死、停止时向用户显示新消息

例如,我有一条消息给用户让我们说:“你好,你好吗”有没有办法在向用户显示之前为这个通知做一些功能,例如用“你好汤姆你好吗”替换上一条消息

并在应用程序关闭未运行时将其保存在 sqllite db 中

4

1 回答 1

2

您可以在下面的代码中处理 android 本机应用程序示例中的静默通知

public class OneSignalSilentNotificationHandler extends NotificationExtenderService {

    @Override
    protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
        // if you want silent notification then return true else false
    //Change title and body according to your requirements
    receivedResult.payload.title = "title";
    receivedResult.payload.body = "body";
    JSONObject
        return false;
    } 

在 AndroidManifest.xml 中放置代码片段

<service
        android:name=".util.OneSignalSilentNotificationHandler"
        android:permission="android.permission.BIND_JOB_SERVICE"
        android:exported="false">
        <intent-filter>
            <action android:name="com.onesignal.NotificationExtender" />
        </intent-filter>
    </service>

这是 Onesignal 文档链接 Onesignal 通知文档

于 2018-11-24T08:19:41.430 回答