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