Search in sources :

Example 86 with RequiresApi

use of androidx.annotation.RequiresApi in project Conversations by siacs.

the class NotificationService method initializeChannels.

@RequiresApi(api = Build.VERSION_CODES.O)
void initializeChannels() {
    final Context c = mXmppConnectionService;
    final NotificationManager notificationManager = c.getSystemService(NotificationManager.class);
    if (notificationManager == null) {
        return;
    }
    notificationManager.deleteNotificationChannel("export");
    notificationManager.deleteNotificationChannel("incoming_calls");
    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("status", c.getString(R.string.notification_group_status_information)));
    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("chats", c.getString(R.string.notification_group_messages)));
    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("calls", c.getString(R.string.notification_group_calls)));
    final NotificationChannel foregroundServiceChannel = new NotificationChannel("foreground", c.getString(R.string.foreground_service_channel_name), NotificationManager.IMPORTANCE_MIN);
    foregroundServiceChannel.setDescription(c.getString(R.string.foreground_service_channel_description, c.getString(R.string.app_name)));
    foregroundServiceChannel.setShowBadge(false);
    foregroundServiceChannel.setGroup("status");
    notificationManager.createNotificationChannel(foregroundServiceChannel);
    final NotificationChannel errorChannel = new NotificationChannel("error", c.getString(R.string.error_channel_name), NotificationManager.IMPORTANCE_LOW);
    errorChannel.setDescription(c.getString(R.string.error_channel_description));
    errorChannel.setShowBadge(false);
    errorChannel.setGroup("status");
    notificationManager.createNotificationChannel(errorChannel);
    final NotificationChannel videoCompressionChannel = new NotificationChannel("compression", c.getString(R.string.video_compression_channel_name), NotificationManager.IMPORTANCE_LOW);
    videoCompressionChannel.setShowBadge(false);
    videoCompressionChannel.setGroup("status");
    notificationManager.createNotificationChannel(videoCompressionChannel);
    final NotificationChannel exportChannel = new NotificationChannel("backup", c.getString(R.string.backup_channel_name), NotificationManager.IMPORTANCE_LOW);
    exportChannel.setShowBadge(false);
    exportChannel.setGroup("status");
    notificationManager.createNotificationChannel(exportChannel);
    final NotificationChannel incomingCallsChannel = new NotificationChannel(INCOMING_CALLS_NOTIFICATION_CHANNEL, c.getString(R.string.incoming_calls_channel_name), NotificationManager.IMPORTANCE_HIGH);
    incomingCallsChannel.setSound(null, null);
    incomingCallsChannel.setShowBadge(false);
    incomingCallsChannel.setLightColor(LED_COLOR);
    incomingCallsChannel.enableLights(true);
    incomingCallsChannel.setGroup("calls");
    incomingCallsChannel.setBypassDnd(true);
    incomingCallsChannel.enableVibration(false);
    notificationManager.createNotificationChannel(incomingCallsChannel);
    final NotificationChannel ongoingCallsChannel = new NotificationChannel("ongoing_calls", c.getString(R.string.ongoing_calls_channel_name), NotificationManager.IMPORTANCE_LOW);
    ongoingCallsChannel.setShowBadge(false);
    ongoingCallsChannel.setGroup("calls");
    notificationManager.createNotificationChannel(ongoingCallsChannel);
    final NotificationChannel messagesChannel = new NotificationChannel("messages", c.getString(R.string.messages_channel_name), NotificationManager.IMPORTANCE_HIGH);
    messagesChannel.setShowBadge(true);
    messagesChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT).build());
    messagesChannel.setLightColor(LED_COLOR);
    final int dat = 70;
    final long[] pattern = { 0, 3 * dat, dat, dat };
    messagesChannel.setVibrationPattern(pattern);
    messagesChannel.enableVibration(true);
    messagesChannel.enableLights(true);
    messagesChannel.setGroup("chats");
    notificationManager.createNotificationChannel(messagesChannel);
    final NotificationChannel silentMessagesChannel = new NotificationChannel("silent_messages", c.getString(R.string.silent_messages_channel_name), NotificationManager.IMPORTANCE_LOW);
    silentMessagesChannel.setDescription(c.getString(R.string.silent_messages_channel_description));
    silentMessagesChannel.setShowBadge(true);
    silentMessagesChannel.setLightColor(LED_COLOR);
    silentMessagesChannel.enableLights(true);
    silentMessagesChannel.setGroup("chats");
    notificationManager.createNotificationChannel(silentMessagesChannel);
    final NotificationChannel quietHoursChannel = new NotificationChannel("quiet_hours", c.getString(R.string.title_pref_quiet_hours), NotificationManager.IMPORTANCE_LOW);
    quietHoursChannel.setShowBadge(true);
    quietHoursChannel.setLightColor(LED_COLOR);
    quietHoursChannel.enableLights(true);
    quietHoursChannel.setGroup("chats");
    quietHoursChannel.enableVibration(false);
    quietHoursChannel.setSound(null, null);
    notificationManager.createNotificationChannel(quietHoursChannel);
    final NotificationChannel deliveryFailedChannel = new NotificationChannel("delivery_failed", c.getString(R.string.delivery_failed_channel_name), NotificationManager.IMPORTANCE_DEFAULT);
    deliveryFailedChannel.setShowBadge(false);
    deliveryFailedChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT).build());
    deliveryFailedChannel.setGroup("chats");
    notificationManager.createNotificationChannel(deliveryFailedChannel);
}
Also used : Context(android.content.Context) NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) NotificationManager(android.app.NotificationManager) Builder(androidx.core.app.NotificationCompat.Builder) RequiresApi(androidx.annotation.RequiresApi)

Example 87 with RequiresApi

use of androidx.annotation.RequiresApi in project Douya by DreaminginCodeZH.

the class ResourcesFlusher method flushThemedResourceCache.

@MainThread
@RequiresApi(Build.VERSION_CODES.M)
@SuppressLint("PrivateApi")
private static void flushThemedResourceCache(@NonNull Object themedResourceCache) {
    if (!sThemedResourceCacheClassInitialized) {
        try {
            sThemedResourceCacheClass = Class.forName("android.content.res.ThemedResourceCache");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        sThemedResourceCacheClassInitialized = true;
    }
    if (sThemedResourceCacheClass == null) {
        return;
    }
    if (!sThemedResourceCacheMThemedEntriesFieldInitialized) {
        try {
            sThemedResourceCacheMThemedEntriesField = sThemedResourceCacheClass.getDeclaredField("mThemedEntries");
            sThemedResourceCacheMThemedEntriesField.setAccessible(true);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
        sThemedResourceCacheMThemedEntriesFieldInitialized = true;
    }
    if (sThemedResourceCacheMThemedEntriesField != null) {
        ArrayMap themedEntries = null;
        try {
            themedEntries = (ArrayMap) sThemedResourceCacheMThemedEntriesField.get(themedResourceCache);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        if (themedEntries != null) {
            themedEntries.clear();
        }
    }
    if (!sThemedResourceCacheMUnthemedEntriesFieldInitialized) {
        try {
            sThemedResourceCacheMUnthemedEntriesField = sThemedResourceCacheClass.getDeclaredField("mUnthemedEntries");
            sThemedResourceCacheMUnthemedEntriesField.setAccessible(true);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
        sThemedResourceCacheMUnthemedEntriesFieldInitialized = true;
    }
    if (sThemedResourceCacheMUnthemedEntriesField != null) {
        LongSparseArray unthemedEntries = null;
        try {
            unthemedEntries = (LongSparseArray) sThemedResourceCacheMUnthemedEntriesField.get(themedResourceCache);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        if (unthemedEntries != null) {
            unthemedEntries.clear();
        }
    }
    if (!sThemedResourceCacheMNullThemedEntriesFieldInitialized) {
        try {
            sThemedResourceCacheMNullThemedEntriesField = sThemedResourceCacheClass.getDeclaredField("mNullThemedEntries");
            sThemedResourceCacheMNullThemedEntriesField.setAccessible(true);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
        sThemedResourceCacheMNullThemedEntriesFieldInitialized = true;
    }
    if (sThemedResourceCacheMNullThemedEntriesField != null) {
        LongSparseArray nullThemedEntries = null;
        try {
            nullThemedEntries = (LongSparseArray) sThemedResourceCacheMNullThemedEntriesField.get(themedResourceCache);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        if (nullThemedEntries != null) {
            nullThemedEntries.clear();
        }
    }
}
Also used : LongSparseArray(android.util.LongSparseArray) ArrayMap(android.util.ArrayMap) MainThread(androidx.annotation.MainThread) RequiresApi(androidx.annotation.RequiresApi) SuppressLint(android.annotation.SuppressLint)

Example 88 with RequiresApi

use of androidx.annotation.RequiresApi in project streaming-android by red5pro.

the class PublishService method createNotificationChannel.

@RequiresApi(Build.VERSION_CODES.O)
private String createNotificationChannel(String channelId, String channelName) {
    NotificationChannel chan = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_NONE);
    chan.setLightColor(Color.BLUE);
    chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
    NotificationManager service = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    service.createNotificationChannel(chan);
    return channelId;
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) RequiresApi(androidx.annotation.RequiresApi)

Example 89 with RequiresApi

use of androidx.annotation.RequiresApi in project robolectric by robolectric.

the class ShadowAppOpsManager method noteProxyOpNoThrow.

@RequiresApi(api = Build.VERSION_CODES.S)
@Implementation(minSdk = Build.VERSION_CODES.S)
protected int noteProxyOpNoThrow(Object op, Object attributionSource, Object message, Object ignoredSkipProxyOperation) {
    Preconditions.checkArgument(op instanceof Integer);
    Preconditions.checkArgument(attributionSource instanceof AttributionSource);
    Preconditions.checkArgument(message == null || message instanceof String);
    Preconditions.checkArgument(ignoredSkipProxyOperation instanceof Boolean);
    AttributionSource castedAttributionSource = (AttributionSource) attributionSource;
    return noteProxyOpNoThrow((int) op, castedAttributionSource.getNextPackageName(), castedAttributionSource.getNextUid(), castedAttributionSource.getNextAttributionTag(), (String) message);
}
Also used : AttributionSource(android.content.AttributionSource) RequiresApi(androidx.annotation.RequiresApi) Implementation(org.robolectric.annotation.Implementation)

Example 90 with RequiresApi

use of androidx.annotation.RequiresApi in project robolectric by robolectric.

the class ShadowImsMmTelManager method createForSubscriptionId.

/**
 * Returns only one instance per subscription id.
 */
@RequiresApi(api = VERSION_CODES.Q)
@Implementation
protected static ImsMmTelManager createForSubscriptionId(int subId) {
    if (!SubscriptionManager.isValidSubscriptionId(subId)) {
        throw new IllegalArgumentException("Invalid subscription ID");
    }
    if (existingInstances.containsKey(subId)) {
        return existingInstances.get(subId);
    }
    ImsMmTelManager imsMmTelManager = reflector(ImsMmTelManagerReflector.class).createForSubscriptionId(subId);
    existingInstances.put(subId, imsMmTelManager);
    return imsMmTelManager;
}
Also used : ImsMmTelManager(android.telephony.ims.ImsMmTelManager) RequiresApi(androidx.annotation.RequiresApi) Implementation(org.robolectric.annotation.Implementation)

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