Search in sources :

Example 96 with RequiresApi

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;
}
Also used : NotificationChannel(android.app.NotificationChannel) RequiresApi(androidx.annotation.RequiresApi)

Example 97 with RequiresApi

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);
}
Also used : StatusBarNotification(android.service.notification.StatusBarNotification) RequiresApi(androidx.annotation.RequiresApi)

Example 98 with RequiresApi

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);
    }
}
Also used : JobScheduler(android.app.job.JobScheduler) JobInfo(android.app.job.JobInfo) ComponentName(android.content.ComponentName) RequiresApi(androidx.annotation.RequiresApi)

Example 99 with RequiresApi

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;
}
Also used : StatusBarNotification(android.service.notification.StatusBarNotification) RequiresApi(androidx.annotation.RequiresApi)

Example 100 with RequiresApi

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);
    }
}
Also used : StatusBarNotification(android.service.notification.StatusBarNotification) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) RequiresApi(androidx.annotation.RequiresApi)

Aggregations

RequiresApi (androidx.annotation.RequiresApi)117 NotificationChannel (android.app.NotificationChannel)16 Intent (android.content.Intent)13 SuppressLint (android.annotation.SuppressLint)10 NotificationManager (android.app.NotificationManager)9 Uri (android.net.Uri)9 StatusBarNotification (android.service.notification.StatusBarNotification)9 NonNull (androidx.annotation.NonNull)9 IOException (java.io.IOException)8 Notification (android.app.Notification)6 PendingIntent (android.app.PendingIntent)6 Context (android.content.Context)6 ObjectAnimator (android.animation.ObjectAnimator)5 Bundle (android.os.Bundle)5 ByteBuffer (java.nio.ByteBuffer)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 SecretKey (javax.crypto.SecretKey)5 GestureDescription (android.accessibilityservice.GestureDescription)4 TaskStackBuilder (android.app.TaskStackBuilder)4 Bitmap (android.graphics.Bitmap)4