Skip to content

Commit 2bc4cd0

Browse files
committed
Refactor initialization
1 parent 4b61f2c commit 2bc4cd0

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

com.unity.mobile.notifications/Runtime/Android/AndroidNotificationCenter.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,9 @@ public static bool Initialize()
570570
#elif UNITY_ANDROID
571571
var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
572572
s_CurrentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
573-
var context = s_CurrentActivity.Call<AndroidJavaObject>("getApplicationContext");
574573

575574
var notificationManagerClass = new AndroidJavaClass("com.unity.androidnotifications.UnityNotificationManager");
576-
var notificationManager = notificationManagerClass.CallStatic<AndroidJavaObject>("getNotificationManagerImpl", context, s_CurrentActivity);
577-
notificationManager.Call("setNotificationCallback", new NotificationCallback());
575+
var notificationManager = notificationManagerClass.CallStatic<AndroidJavaObject>("getNotificationManagerImpl", s_CurrentActivity, new NotificationCallback());
578576
s_Jni = new JniApi(notificationManagerClass, notificationManager);
579577

580578
s_Initialized = true;

com.unity.mobile.notifications/Runtime/Android/Plugins/com/unity/androidnotifications/UnityNotificationManager.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ public class UnityNotificationManager extends BroadcastReceiver {
7171
static final String NOTIFICATION_IDS_SHARED_PREFS = "UNITY_STORED_NOTIFICATION_IDS";
7272
static final String NOTIFICATION_IDS_SHARED_PREFS_KEY = "UNITY_NOTIFICATION_IDS";
7373

74-
private void initialize(Activity activity) {
74+
private void initialize(Activity activity, NotificationCallback notificationCallback) {
7575
if (mContext == null)
7676
mContext = activity.getApplicationContext();
7777
mActivity = activity;
7878
if (mBackgroundThread == null)
7979
mBackgroundThread = new UnityNotificationBackgroundThread(mContext, mScheduledNotifications);
8080
if (mRandom == null)
8181
mRandom = new Random();
82+
mNotificationCallback = notificationCallback;
8283

8384
try {
8485
ApplicationInfo ai = activity.getPackageManager().getApplicationInfo(activity.getPackageName(), PackageManager.GET_META_DATA);
@@ -117,12 +118,12 @@ public static synchronized UnityNotificationManager getNotificationManagerImpl(C
117118
}
118119

119120
// Called from managed code.
120-
public static synchronized UnityNotificationManager getNotificationManagerImpl(Context context, Activity activity) {
121+
public static synchronized UnityNotificationManager getNotificationManagerImpl(Activity activity, NotificationCallback notificationCallback) {
121122
if (mUnityNotificationManager == null) {
122123
mUnityNotificationManager = new UnityNotificationManager();
123124
}
124125

125-
mUnityNotificationManager.initialize(activity);
126+
mUnityNotificationManager.initialize(activity, notificationCallback);
126127
return mUnityNotificationManager;
127128
}
128129

@@ -135,11 +136,6 @@ public static NotificationManager getNotificationManager(Context context) {
135136
return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
136137
}
137138

138-
// Called from managed code.
139-
public void setNotificationCallback(NotificationCallback notificationCallback) {
140-
UnityNotificationManager.mNotificationCallback = notificationCallback;
141-
}
142-
143139
public void registerNotificationChannel(
144140
String id,
145141
String name,

0 commit comments

Comments
 (0)