为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用 OneSignal 打开特定活动?

如何使用 OneSignal 打开特定活动?

LEATH 2021-06-01 09:49:47
我正在使用 onesignal 发送推送通知。我使用此示例代码在用户单击推送通知时打开特定活动。如果我想打开另一个特定的活动,我应该怎么做? package com.moho.app;    import android.content.Intent;    import android.util.Log;    import android.widget.Toast;    import com.onesignal.OSNotificationAction;    import com.onesignal.OSNotificationOpenResult;    import com.onesignal.OneSignal;    import org.json.JSONObject;    public class MyNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {        // This fires when a notification is opened by tapping on it.        @Override        public void notificationOpened(OSNotificationOpenResult result) {            OSNotificationAction.ActionType actionType = result.action.type;            JSONObject data = result.notification.payload.additionalData;            String activityToBeOpened;            String activity;            //While sending a Push notification from OneSignal dashboard            // you can send an addtional data named "activityToBeOpened" and retrieve the value of it and do necessary operation            //If key is "activityToBeOpened" and value is "AnotherActivity", then when a user clicks            //on the notification, AnotherActivity will be opened.            //Else, if we have not set any additional data MainActivity is opened.            if (data != null) {                activityToBeOpened = data.optString("activityToBeOpened", null);                if (activityToBeOpened != null && activityToBeOpened.equals("AnotherActivity")) {                    Log.i("OneSignalExample", "customkey set with value: " + activityToBeOpened);                    Intent intent = new Intent(MainMenu.getContext(), AboutUs.class);                    intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);                    MainMenu.getContext().startActivity(intent);
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 147 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信