use of androidx.annotation.RequiresApi in project OneSignal-Android-SDK by OneSignal.
the class NotificationChannelManager method createDefaultChannel.
@RequiresApi(api = Build.VERSION_CODES.O)
private static String createDefaultChannel(NotificationManager notificationManager) {
NotificationChannel channel = new NotificationChannel(DEFAULT_CHANNEL_ID, "Miscellaneous", NotificationManager.IMPORTANCE_DEFAULT);
channel.enableLights(true);
channel.enableVibration(true);
notificationManager.createNotificationChannel(channel);
return DEFAULT_CHANNEL_ID;
}
use of androidx.annotation.RequiresApi in project OneSignal-Android-SDK by OneSignal.
the class BadgeCountUpdater method updateStandard.
@RequiresApi(api = Build.VERSION_CODES.M)
private static void updateStandard(Context context) {
StatusBarNotification[] activeNotifs = OneSignalNotificationManager.getActiveNotifications(context);
int runningCount = 0;
for (StatusBarNotification activeNotif : activeNotifs) {
if (NotificationLimitManager.isGroupSummary(activeNotif))
continue;
runningCount++;
}
updateCount(runningCount, context);
}
use of androidx.annotation.RequiresApi in project OneSignal-Android-SDK by OneSignal.
the class OSBackgroundSync method scheduleSyncServiceAsJob.
@RequiresApi(21)
private void scheduleSyncServiceAsJob(Context context, long delayMs) {
OneSignal.Log(OneSignal.LOG_LEVEL.VERBOSE, "OSBackgroundSync scheduleSyncServiceAsJob:atTime: " + delayMs);
if (isJobIdRunning(context)) {
OneSignal.Log(OneSignal.LOG_LEVEL.VERBOSE, "OSBackgroundSync scheduleSyncServiceAsJob Scheduler already running!");
// If a JobScheduler is schedule again while running it will stop current job. We will schedule again when finished.
// This will avoid InterruptionException due to thread.join() or queue.take() running.
needsJobReschedule = true;
return;
}
JobInfo.Builder jobBuilder = new JobInfo.Builder(getSyncTaskId(), new ComponentName(context, getSyncServiceJobClass()));
jobBuilder.setMinimumLatency(delayMs).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
if (hasBootPermission(context))
jobBuilder.setPersisted(true);
JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
try {
int result = jobScheduler.schedule(jobBuilder.build());
OneSignal.Log(OneSignal.LOG_LEVEL.INFO, "OSBackgroundSync scheduleSyncServiceAsJob:result: " + result);
} catch (NullPointerException e) {
// Catch for buggy Oppo devices
// https://github.com/OneSignal/OneSignal-Android-SDK/issues/487
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "scheduleSyncServiceAsJob called JobScheduler.jobScheduler which " + "triggered an internal null Android error. Skipping job.", e);
}
}
use of androidx.annotation.RequiresApi in project OneSignal-Android-SDK by OneSignal.
the class OneSignalNotificationManager method getGrouplessNotifsCount.
/**
* Iterate over all active notifications and count the groupless ones
* and return the int count
*/
@RequiresApi(api = Build.VERSION_CODES.M)
static Integer getGrouplessNotifsCount(Context context) {
StatusBarNotification[] statusBarNotifications = getActiveNotifications(context);
int groupCount = 0;
for (StatusBarNotification statusBarNotification : statusBarNotifications) {
if (!NotificationCompat.isGroupSummary(statusBarNotification.getNotification()) && GROUPLESS_SUMMARY_KEY.equals(statusBarNotification.getNotification().getGroup())) {
groupCount++;
}
}
return groupCount;
}
use of androidx.annotation.RequiresApi in project OneSignal-Android-SDK by OneSignal.
the class OneSignalNotificationManager method assignGrouplessNotifications.
/**
* All groupless notifications are assigned the GROUPLESS_SUMMARY_KEY and notify() is called
*/
@RequiresApi(api = Build.VERSION_CODES.M)
static void assignGrouplessNotifications(Context context, ArrayList<StatusBarNotification> grouplessNotifs) {
for (StatusBarNotification grouplessNotif : grouplessNotifs) {
Notification.Builder grouplessNotifBuilder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
grouplessNotifBuilder = Notification.Builder.recoverBuilder(context, grouplessNotif.getNotification());
} else {
grouplessNotifBuilder = new Notification.Builder(context);
}
// Recreate the notification but with the groupless key instead
Notification notif = grouplessNotifBuilder.setGroup(GROUPLESS_SUMMARY_KEY).build();
NotificationManagerCompat.from(context).notify(grouplessNotif.getId(), notif);
}
}
Aggregations