点击通知栏并在应用终止时打开通知活动(onesignal)

时间:2019-07-12 05:33:17

标签: android push-notification onesignal

您好,我正在使用onesignal服务开发android推送通知功能。现在我遇到了一个小问题。

应用运行正常,当应用被杀死时,当应用在后台运行时,会收到通知。

(在通知栏上,同时在后台和前台打开活动)

但是当收到从任务管理器通知中终止的应用程序时,

但是我无法打开它(“ OneNewsView”活动)无法将通知数据发送到我的“ OneNewsView”活动中。

这是我的代码

    OneSignal.startInit(this)                
         .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
            .unsubscribeWhenNotificationsAreDisabled(true)
            .setNotificationReceivedHandler(new ExampleNotificationReceivedHandler())
            .setNotificationOpenedHandler(new NotificationOpenHandler())
            .init();



class NotificationOpenHandler implements OneSignal.NotificationOpenedHandler {
    // This fires when a notification is opened by tapping on it.
    @Override
    public void notificationOpened(OSNotificationOpenResult result) {
        Log.i("OneSignalExample", "customkey set with value: ");
        OSNotificationAction.ActionType actionType = result.action.type;
        JSONObject data = result.notification.payload.additionalData;
        String type,id;

        Intent intent = new Intent(getApplicationContext(), OneNewsView.class);

        if (data != null) {
            type = data.optString("Type", null);
            id = data.optString("Id", null);
            if (type != null && id !=null ){
                if(type.equals("News")){

                    intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.putExtra("type",type);
                    intent.putExtra("newsid",id);
                    startActivity(intent);
                }
                else{
                    Log.i("OneSignalExample", "else" );
                }
            }
            else {
                Log.i("OneSignalExample", "customkey set with value: ");
            }
        }

        if (actionType == OSNotificationAction.ActionType.ActionTaken)
            Log.i("OneSignalExample", "Button pressed with id: " + result.action.actionID);


    }
}

我只想要这个, 当应用终止时,收到通知后,请点击通知栏并打开Notification Activity(OneNewsView“活动)。

谢谢

1 个答案:

答案 0 :(得分:0)


Google FCM也存在此问题。我只是将data部分发送给客户端以解决此问题。 data部分包含密钥对。如果您的应用程序不存在于内存中,则如果您的推送中有data部分,则将运行通知服务。但是如果您在Google FCM中发送简单的通知,则发送“通知”只会显示简单的通知栏,如果您单击它,则使用Intent Fillter Louncher & Main

打开活动

this article关于一个信号中的这个问题(我认为不是问题)

希望获得帮助

相关问题