Meeting SDK for Android API Reference
Loading...
Searching...
No Matches
SDKNotificationMgr.java
Go to the documentation of this file.
1package us.zoom.sdk;
2
3import android.app.Activity;
4import android.app.Notification;
5import android.app.NotificationChannel;
6import android.app.NotificationManager;
7import android.app.PendingIntent;
8import android.app.Service;
9import android.content.Context;
10import android.content.Intent;
11import android.content.pm.ServiceInfo;
12import android.graphics.Bitmap;
13import android.graphics.BitmapFactory;
14import android.os.Build;
15
16import androidx.annotation.NonNull;
17import androidx.annotation.Nullable;
18import androidx.annotation.RequiresApi;
19import androidx.core.app.NotificationCompat;
20import androidx.core.graphics.drawable.IconCompat;
21
22import com.zipow.videobox.IntegrationActivity;
23import com.zipow.videobox.VideoBoxApplication;
24import com.zipow.videobox.common.user.PTSettingHelper;
25import com.zipow.videobox.confapp.CmmUser;
26import com.zipow.videobox.conference.model.intent.ZmIntegrationActionType;
27import com.zipow.videobox.sdk.SDKConstants;
28import com.zipow.videobox.sdk.ZmSdkHelper;
29import com.zipow.videobox.util.NotificationMgr;
30
31import java.util.List;
32
33import us.zoom.business.utils.ZmBusinessSettings;
34import us.zoom.common.crossplatform.cmmlib.BuildConfig;
35import us.zoom.core.helper.ZMLog;
36import us.zoom.internal.SDKCustomizedMeetingUIHelper;
37import us.zoom.internal.helper.SDKMeetingInterfaceHelper;
38import us.zoom.libtools.storage.PreferenceUtil;
39
40import us.zoom.libtools.utils.ZmIntentUtils;
41import us.zoom.libtools.utils.ZmOsUtils;
42import us.zoom.libtools.utils.ZmStringUtils;
43import us.zoom.util.AndroidContext;
44import us.zoom.videomeetings.R;
45
46public class SDKNotificationMgr {
48 private static long s_lastWaitingRoomNotificationTime = 0;
49
51 mNotifData = data;
52 }
53
54 @RequiresApi(api = Build.VERSION_CODES.N)
55 private static int convertPriority2O(int notificationPriority){
56 switch(notificationPriority){
57 case NotificationCompat.PRIORITY_DEFAULT:
58 return NotificationManager.IMPORTANCE_DEFAULT;
59 case NotificationCompat.PRIORITY_HIGH:
60 return NotificationManager.IMPORTANCE_HIGH;
61 case NotificationCompat.PRIORITY_MAX:
62 return NotificationManager.IMPORTANCE_HIGH;
63 case NotificationCompat.PRIORITY_LOW:
64 return NotificationManager.IMPORTANCE_LOW;
65 case NotificationCompat.PRIORITY_MIN:
66 return NotificationManager.IMPORTANCE_MIN;
67 default:
68 return NotificationManager.IMPORTANCE_DEFAULT;
69 }
70 }
71
72 @RequiresApi(api = Build.VERSION_CODES.N)
73 public static NotificationCompat.Builder getNotificationCompatBuilder4SDK(Context context, String channelId, int notificationPriority) {
74 notificationPriority = convertPriority2O(notificationPriority);
75 NotificationCompat.Builder builder;
76 String mChannelId = channelId;
77 if (ZmStringUtils.isEmptyOrNull(mChannelId))
78 mChannelId = NotificationMgr.getNotificationChannelId();
79 if (ZmOsUtils.isAtLeastO()) {
80 NotificationManager notificationMgr = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE);
81 NotificationChannel notificationChannel = notificationMgr.getNotificationChannel(mChannelId);
82 if (notificationChannel == null) {
83 notificationChannel = new NotificationChannel(mChannelId, context.getResources().getString(R.string.zm_notification_channel_name_43235), notificationPriority);
84 notificationChannel.enableVibration(ZmBusinessSettings.getPlayAlertVibrate());
85 if (notificationChannel.canShowBadge())
86 notificationChannel.setShowBadge(false);
87 } else {
88 notificationChannel.setImportance(notificationPriority);
89 }
90 if (notificationMgr != null) {
91 notificationMgr.createNotificationChannel(notificationChannel);
92 }
93 builder = new NotificationCompat.Builder(context, mChannelId);
94 } else {
95 builder = new NotificationCompat.Builder(context);
96 }
97
98 return builder;
99 }
100
101 @RequiresApi(api = Build.VERSION_CODES.N)
102 public static NotificationCompat.Builder getNotificationCompatBuilder(Context context,String channelId, int notificationPriority) {
103 notificationPriority = convertPriority2O(notificationPriority);
104 NotificationCompat.Builder builder = null;
105 if(ZmOsUtils.isAtLeastO()) {
106 NotificationManager notificationMgr = (NotificationManager)context
107 .getSystemService(Activity.NOTIFICATION_SERVICE);
108 NotificationChannel notificationChannel = notificationMgr.getNotificationChannel(channelId);
109 if(notificationChannel == null) {
110 notificationChannel = new NotificationChannel(NotificationMgr.getNotificationChannelId(),
111 context.getResources().getString(R.string.zm_notification_channel_name_43235),notificationPriority);
112 notificationChannel.enableVibration(ZmBusinessSettings.getPlayAlertVibrate());
113 if (notificationChannel.canShowBadge())
114 notificationChannel.setShowBadge(false);
115 }else {
116 notificationChannel.setImportance(notificationPriority);
117 }
118 if(notificationMgr != null) {
119 notificationMgr.createNotificationChannel(notificationChannel);
120 }
121 builder = new NotificationCompat.Builder(context, NotificationMgr.getNotificationChannelId());
122 }else {
123 builder = new NotificationCompat.Builder(context);
124 }
125 return builder;
126 }
127
128 public static void showConfNotificationForSDK(@NonNull Context context, boolean isForceShow) {
129 int defaultForegroundServiceType = 0;
130 if (ZmOsUtils.isAtLeastU()) {
131 defaultForegroundServiceType = SDKMeetingInterfaceHelper.getDefaultForegroundServiceType();
132 }
133 showConfNotificationForSDK(context, isForceShow, defaultForegroundServiceType);
134 }
135
136 public static void showConfNotificationForSDK(@NonNull Context context, boolean isForceShow,int foregroundServiceType) {
137 if (!isForceShow) {
138 boolean enableShowNotification = PreferenceUtil.readBooleanValue(SDKConstants.SDK_ENABLE_CONF_NOTIFICATION, true);
139 if (!enableShowNotification) {
140 return;
141 }
142 }
143 int notificationPriority = PreferenceUtil.readIntValue(SDKConstants.SDK_MEETING_NOTIFICATION_PRIORITY, Notification.PRIORITY_DEFAULT);
144 Intent clickIntent = new Intent(context, IntegrationActivity.class);
145 clickIntent.setAction(ZmIntegrationActionType.ACTION_RETURN_TO_CONF);
146
147 PendingIntent contentIntent = ZmIntentUtils.getPendingIntentActivity(context,0, clickIntent, PendingIntent.FLAG_CANCEL_CURRENT);
148
149 int contentTitleId = R.string.zm_app_name;
150 int contentTextId = R.string.zm_msg_conf_in_progress;
151 int smallIconId = R.drawable.zm_conf_notification;
152 int smallIconForLorLaterId = R.drawable.zm_conf_notification_5_0;
153 int bgColorId = R.color.zm_notification_icon_bg;
154 int largeIconId = R.drawable.zm_launcher;
155 if (mNotifData != null) {
156 if (mNotifData.getContentTitleId() != 0) {
157 contentTitleId = mNotifData.getContentTitleId();
158 }
159 if(mNotifData.getContentTextId() != 0) {
160 contentTextId = mNotifData.getContentTextId();
161 }
162 if(mNotifData.getSmallIconId() != 0) {
163 smallIconId = mNotifData.getSmallIconId();
164 try {
165 context.getDrawable(smallIconId);
166 } catch (Exception e) {
167 smallIconId = R.drawable.zm_conf_notification;
168 }
169 }
171 smallIconForLorLaterId = mNotifData.getSmallIconForLorLaterId();
172 try {
173 context.getDrawable(smallIconForLorLaterId);
174 } catch (Exception e) {
175 smallIconForLorLaterId = R.drawable.zm_conf_notification_5_0;
176 }
177 }
178 if(mNotifData.getBgColorId() != 0) {
179 bgColorId = mNotifData.getBgColorId();
180 }
181 if(mNotifData.getLargeIconId() != 0) {
182 largeIconId = mNotifData.getLargeIconId();
183 try {
184 context.getDrawable(largeIconId);
185 } catch (Exception e) {
186 largeIconId = R.drawable.zm_launcher;
187 }
188 }
189 }
190 if (ZmOsUtils.isAtLeastL()) {
191 smallIconId = smallIconForLorLaterId;
192 }
193
194 IconCompat smallIcon;
195 try {
196 if (SDKMeetingInterfaceHelper.isUsingDynamicFeature()) {
197 smallIcon = IconCompat.createWithBitmap(BitmapFactory.decodeResource(context.getResources(), smallIconId));
198 } else {
199 smallIcon = IconCompat.createWithResource(context, smallIconId);
200 }
201 } catch (Exception e) {
202 if (BuildConfig.LOG_ENABLE) {
203 ZMLog.e("showConfNotificationForSDK", e, "createWithResource");
204 }
205 smallIcon = IconCompat.createWithBitmap(BitmapFactory.decodeResource(context.getResources(), R.drawable.zm_conf_notification_5_0));
206 }
207
208 String contentTitle;
209 String contentText;
210 int color;
211 try {
212 contentTitle = context.getString(contentTitleId);
213 } catch (Exception e) {
214 contentTitle = context.getString(R.string.zm_app_name);
215 }
216 try {
217 contentText = context.getString(contentTextId);
218 } catch (Exception e) {
219 contentText = context.getString(R.string.zm_msg_conf_in_progress);
220 }
221 try {
222 color = context.getResources().getColor(bgColorId);
223 } catch (Exception e) {
224 color = context.getResources().getColor(R.color.zm_notification_icon_bg);
225 }
226
227 Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), largeIconId);
228
229 NotificationCompat.Builder builder = null;
230
231 //noinspection ConstantConditions
232 builder = new NotificationCompat.Builder(context.getApplicationContext());
233 if (ZmOsUtils.isAtLeastO()) {
234 String channelId = PreferenceUtil.readStringValue(SDKConstants.SDK_CONF_NOTIFICATION_CHANNEL_ID, "");
235 builder = getNotificationCompatBuilder4SDK(context.getApplicationContext(), channelId, notificationPriority);
236 }
237
238 if (ZmOsUtils.isAtLeastL()) {
239 String category = PreferenceUtil.readStringValue(SDKConstants.SDK_CONF_NOTIFICATION_CATEGORY, "");
240 if(!ZmStringUtils.isEmptyOrNull(category)){
241 builder.setCategory(category);
242 }
243 }
244
245 builder.setWhen(0)
246 .setAutoCancel(false)
247 .setOngoing(true)
248 .setSmallIcon(smallIcon)
249 .setColor(color)
250 .setContentTitle(contentTitle)
251 .setContentText(contentText)
252 .setOnlyAlertOnce(true)
253 .setContentIntent(contentIntent)
254 .setPriority(notificationPriority);
255
256
257 if (ZmOsUtils.isAtLeastL() && context.getResources().getBoolean(R.bool.zm_config_show_large_icon_in_notification_on_api21_above)) {
258 builder.setLargeIcon(largeIcon);
259 }
260
261 Notification notification = builder.build();
262 if (isForceShow) {
263 if(context instanceof Service){
264 if (ZmOsUtils.isAtLeastU()) {
265 ((Service)context).startForeground(NotificationMgr.PT_NOTIFICATION_ID, notification, foregroundServiceType);
266 }else {
267 ((Service)context).startForeground(NotificationMgr.PT_NOTIFICATION_ID, notification);
268 }
269 return;
270 }
271 }
272 NotificationManager notificationMgr = (NotificationManager)context.getSystemService(Activity.NOTIFICATION_SERVICE);
273 if (null != notificationMgr)
274 notificationMgr.notify(NotificationMgr.PT_NOTIFICATION_ID,notification);
275 }
276 public static void showConfNotificationForSDK(@NonNull Context context) {
277 Intent clickIntent = new Intent(context, IntegrationActivity.class);
278 clickIntent.setAction(ZmIntegrationActionType.ACTION_RETURN_TO_CONF);
279
280 PendingIntent contentIntent = ZmIntentUtils.getPendingIntentActivity(context, 0, clickIntent, PendingIntent.FLAG_CANCEL_CURRENT);
281
282 String contentTitle = context.getString(R.string.zm_app_name);
283 String contentText = context.getString(R.string.zm_msg_conf_in_progress);
284 int smallIconId = R.drawable.zm_conf_notification;
285 if (ZmOsUtils.isAtLeastL()) {
286 smallIconId = R.drawable.zm_conf_notification_5_0;
287 }
288 IconCompat smallIcon = IconCompat.createWithBitmap(BitmapFactory.decodeResource(context.getResources(), smallIconId));
289
290 int color = context.getResources().getColor(R.color.zm_notification_icon_bg);
291
292 Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.zm_launcher);
293
294 NotificationCompat.Builder builder = null;
295
296 //noinspection ConstantConditions
297 if (((VideoBoxApplication)VideoBoxApplication.getInstance()).isSDKMode()) {
298 builder = new NotificationCompat.Builder(context.getApplicationContext());
299 if (ZmOsUtils.isAtLeastO()) {
300 String channelId = PreferenceUtil.readStringValue(SDKConstants.SDK_CONF_NOTIFICATION_CHANNEL_ID, "");
301 if (!ZmStringUtils.isEmptyOrNull(channelId))
302 {
303 builder.setChannelId(channelId);
304 }else {
305 builder = NotificationMgr.getNotificationCompatBuilder(context.getApplicationContext(), false);
306 }
307 }
308 if (ZmOsUtils.isAtLeastL()) {
309 String category = PreferenceUtil.readStringValue(SDKConstants.SDK_CONF_NOTIFICATION_CATEGORY, "");
310 if(!ZmStringUtils.isEmptyOrNull(category)){
311 builder.setCategory(category);
312 }
313 }
314 } else {
315 builder = NotificationMgr.getNotificationCompatBuilder(context.getApplicationContext(), false);
316 }
317
318 builder.setWhen(0)
319 .setAutoCancel(false)
320 .setOngoing(true)
321 .setSmallIcon(smallIcon)
322 .setColor(color)
323 .setContentTitle(contentTitle)
324 .setContentText(contentText)
325 .setOnlyAlertOnce(true)
326 .setContentIntent(contentIntent);
327
328
329 if (ZmOsUtils.isAtLeastL() && context.getResources().getBoolean(R.bool.zm_config_show_large_icon_in_notification_on_api21_above)) {
330 builder.setLargeIcon(largeIcon);
331 }
332
333 Notification notification = builder.build();
334 NotificationManager notificationMgr = (NotificationManager)context.getSystemService(Activity.NOTIFICATION_SERVICE);
335 //noinspection ConstantConditions
336 notificationMgr.notify(NotificationMgr.PT_NOTIFICATION_ID,notification);
337 }
338
339 public static void showWaitingRoomNotificationForSDK(@Nullable Context context, @NonNull List<CmmUser> userList) {
340 boolean enableShowNotification = PreferenceUtil.readBooleanValue(SDKConstants.SDK_ENABLE_CONF_NOTIFICATION, true);
341 if (SDKCustomizedMeetingUIHelper.isSdkUsingCustomizedMeetingUI() || !enableShowNotification || context == null) {
342 return;
343 }
344 NotificationManager notificationMgr = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE);
345
346 Intent clickIntent = new Intent(context, IntegrationActivity.class);
347 clickIntent.setAction(ZmIntegrationActionType.ACTION_RETURN_TO_PLIST);
348
349 PendingIntent contentIntent = ZmIntentUtils.getPendingIntentActivity(context, 0, clickIntent, PendingIntent.FLAG_CANCEL_CURRENT);
350
351 int contentTitleId = R.string.zm_app_name;
352 int smallIconId = R.drawable.zm_conf_notification;
353 int smallIconForLorLaterId = R.drawable.zm_conf_notification_5_0;
354 int bgColorId = R.color.zm_notification_icon_bg;
355 if (mNotifData != null) {
356 if (mNotifData.getContentTitleId() != 0) {
357 contentTitleId = mNotifData.getContentTitleId();
358 }
359 if(mNotifData.getSmallIconId() != 0) {
360 smallIconId = mNotifData.getSmallIconId();
361 try {
362 context.getDrawable(smallIconId);
363 } catch (Exception e) {
364 smallIconId = R.drawable.zm_conf_notification;
365 }
366 }
368 smallIconForLorLaterId = mNotifData.getSmallIconForLorLaterId();
369 try {
370 context.getDrawable(smallIconForLorLaterId);
371 } catch (Exception e) {
372 smallIconForLorLaterId = R.drawable.zm_conf_notification_5_0;
373 }
374 }
375 if(mNotifData.getBgColorId() != 0) {
376 bgColorId = mNotifData.getBgColorId();
377 }
378 }
379 String contentText;
380 int count = userList.size();
381 if (count == 1) {
382 contentText = context.getString(R.string.zm_waiting_room_one_entered_msg_153844, userList.get(0).getScreenName());
383 } else if (count > 1) {
384 contentText = context.getString(R.string.zm_waiting_room_multiple_entered_msg_153844, count);
385 } else {
386 if (notificationMgr != null) {
387 try {
388 notificationMgr.cancel(NotificationMgr.WAITING_ROOM_NOTIFICATION_ID);
389 } catch (Exception e) {
390 if (BuildConfig.LOG_ENABLE)
391 ZMLog.w("showWaitingRoomNotificationForSDK", e, "cancelWaitingRoomNotification exception");
392 }
393 }
394 return;
395 }
396
397 if (ZmOsUtils.isAtLeastL()) {
398 smallIconId = smallIconForLorLaterId;
399 }
400
401 IconCompat smallIcon;
402
403 try {
404 if (SDKMeetingInterfaceHelper.isUsingDynamicFeature()) {
405 smallIcon = IconCompat.createWithBitmap(BitmapFactory.decodeResource(context.getResources(), smallIconId));
406 } else {
407 smallIcon = IconCompat.createWithResource(context, smallIconId);
408 }
409 } catch (Exception e) {
410 if (BuildConfig.LOG_ENABLE) {
411 ZMLog.e("showWaitingRoomNotificationForSDK", e, "createWithResource");
412 }
413 smallIcon = IconCompat.createWithBitmap(BitmapFactory.decodeResource(context.getResources(), R.drawable.zm_conf_notification_5_0));
414 }
415
416 String contentTitle;
417 int color;
418 try {
419 contentTitle = context.getString(contentTitleId);
420 } catch (Exception e) {
421 contentTitle = context.getString(R.string.zm_app_name);
422 }
423 try {
424 color = context.getResources().getColor(bgColorId);
425 } catch (Exception e) {
426 color = context.getResources().getColor(R.color.zm_notification_icon_bg);
427 }
428
429 NotificationCompat.Builder builder = NotificationMgr.getNotificationCompatBuilder(context.getApplicationContext())
430 .setSmallIcon(smallIcon)
431 .setColor(color)
432 .setContentTitle(contentTitle)
433 .setContentText(contentText)
434 .setContentIntent(contentIntent)
435 .setPriority(NotificationCompat.PRIORITY_HIGH)
436 .setTicker(contentText)
437 .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
438 .setAutoCancel(true)
439 .setOnlyAlertOnce(true);
440
441 Notification notification = builder.build();
442 long curTime = System.currentTimeMillis();
444 return; //do not repeat it too quick
445 }
446 if (notificationMgr != null) {
447 try {
448 notificationMgr.notify(NotificationMgr.WAITING_ROOM_NOTIFICATION_ID, notification);
450 } catch (Exception e) {
451 if (BuildConfig.LOG_ENABLE)
452 ZMLog.w("showWaitingRoomNotificationForSDK", e, "showWaitingRoomNotification exception");
453 }
454 }
455 }
456}
static void setCustomizedNotificationData(CustomizedNotificationData data)
static void showConfNotificationForSDK(@NonNull Context context)
static void showWaitingRoomNotificationForSDK(@Nullable Context context, @NonNull List< CmmUser > userList)
static void showConfNotificationForSDK(@NonNull Context context, boolean isForceShow, int foregroundServiceType)
static NotificationCompat.Builder getNotificationCompatBuilder(Context context, String channelId, int notificationPriority)
static int convertPriority2O(int notificationPriority)
static CustomizedNotificationData mNotifData
static void showConfNotificationForSDK(@NonNull Context context, boolean isForceShow)
static NotificationCompat.Builder getNotificationCompatBuilder4SDK(Context context, String channelId, int notificationPriority)