我正在使用 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);
添加回答
舉報
0/150
提交
取消