我正在使用 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);
相关分类