Search in sources :

Example 96 with NotificationChannel

use of android.app.NotificationChannel in project Etar-Calendar by Etar-Group.

the class AlertService method createChannels.

public static void createChannels(Context context) {
    if (Utils.isOreoOrLater()) {
        // Create notification channel
        NotificationMgr nm = new NotificationMgrWrapper((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE));
        NotificationChannel channel = new NotificationChannel(ALERT_CHANNEL_ID, context.getString(R.string.standalone_app_label), NotificationManager.IMPORTANCE_HIGH);
        channel.enableLights(true);
        NotificationChannel foregroundChannel = new NotificationChannel(FOREGROUND_CHANNEL_ID, context.getString(R.string.foreground_notification_channel_name), NotificationManager.IMPORTANCE_LOW);
        foregroundChannel.setDescription(context.getString(R.string.foreground_notification_channel_description));
        nm.createNotificationChannel(channel);
        nm.createNotificationChannel(foregroundChannel);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel)

Example 97 with NotificationChannel

use of android.app.NotificationChannel in project phonegap-plugin-push by phonegap.

the class PushPlugin method listChannels.

@TargetApi(26)
private JSONArray listChannels() throws JSONException {
    JSONArray channels = new JSONArray();
    // only call on Android O and above
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        final NotificationManager notificationManager = (NotificationManager) cordova.getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
        List<NotificationChannel> notificationChannels = notificationManager.getNotificationChannels();
        for (NotificationChannel notificationChannel : notificationChannels) {
            JSONObject channel = new JSONObject();
            channel.put(CHANNEL_ID, notificationChannel.getId());
            channel.put(CHANNEL_DESCRIPTION, notificationChannel.getDescription());
            channels.put(channel);
        }
    }
    return channels;
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TargetApi(android.annotation.TargetApi)

Example 98 with NotificationChannel

use of android.app.NotificationChannel in project Signal-Android by WhisperSystems.

the class MainActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (Build.VERSION.SDK_INT > 26) {
        NotificationChannel deviceTransfer = new NotificationChannel(TRANSFER_NOTIFICATION_CHANNEL, "Device Transfer", NotificationManager.IMPORTANCE_DEFAULT);
        NotificationManagerCompat.from(this).createNotificationChannel(deviceTransfer);
    }
    list = findViewById(R.id.list);
    final TransferNotificationData data = new TransferNotificationData(1337, TRANSFER_NOTIFICATION_CHANNEL, R.drawable.ic_refresh_20);
    findViewById(R.id.start_server).setOnClickListener(v -> {
        DeviceToDeviceTransferService.startServer(this, new ServerReceiveRandomBytes(), data, PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0));
        list.removeAllViews();
    });
    findViewById(R.id.start_client).setOnClickListener(v -> {
        DeviceToDeviceTransferService.startClient(this, new ClientSendRandomBytes(), data, PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0));
        list.removeAllViews();
    });
    findViewById(R.id.stop).setOnClickListener(v -> DeviceToDeviceTransferService.stop(this));
    findViewById(R.id.enable_permission).setOnClickListener(v -> {
        if (Build.VERSION.SDK_INT >= 23 && checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, 420);
        }
    });
    EventBus.getDefault().register(this);
}
Also used : NotificationChannel(android.app.NotificationChannel) TransferNotificationData(org.signal.devicetransfer.DeviceToDeviceTransferService.TransferNotificationData) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 99 with NotificationChannel

use of android.app.NotificationChannel in project Signal-Android by WhisperSystems.

the class NotificationChannels method createChannelFor.

/**
 * More verbose version of {@link #createChannelFor(Context, Recipient)}.
 */
@Nullable
public static synchronized String createChannelFor(@NonNull Context context, @NonNull String channelId, @NonNull String displayName, @Nullable Uri messageSound, boolean vibrationEnabled, @Nullable String shortcutId) {
    if (!supported()) {
        return null;
    }
    NotificationChannel channel = new NotificationChannel(channelId, displayName, NotificationManager.IMPORTANCE_HIGH);
    setLedPreference(channel, SignalStore.settings().getMessageLedColor());
    channel.setGroup(CATEGORY_MESSAGES);
    setVibrationEnabled(channel, vibrationEnabled);
    if (messageSound != null) {
        channel.setSound(messageSound, new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN).setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT).build());
    }
    if (Build.VERSION.SDK_INT >= CONVERSATION_SUPPORT_VERSION && shortcutId != null) {
        channel.setConversationId(getMessagesChannel(context), shortcutId);
    }
    NotificationManager notificationManager = ServiceUtil.getNotificationManager(context);
    notificationManager.createNotificationChannel(channel);
    return channelId;
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) Nullable(androidx.annotation.Nullable)

Example 100 with NotificationChannel

use of android.app.NotificationChannel in project Signal-Android by WhisperSystems.

the class NotificationChannels method isCallsChannelValid.

public static boolean isCallsChannelValid(@NonNull Context context) {
    if (!supported()) {
        return true;
    }
    NotificationManager notificationManager = ServiceUtil.getNotificationManager(context);
    NotificationChannel channel = notificationManager.getNotificationChannel(CALLS);
    return channel != null && channel.getImportance() == NotificationManager.IMPORTANCE_HIGH;
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager)

Aggregations

NotificationChannel (android.app.NotificationChannel)762 Test (org.junit.Test)430 NotificationBackend (com.android.settings.notification.NotificationBackend)215 NotificationManager (android.app.NotificationManager)210 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)114 Intent (android.content.Intent)87 Preference (androidx.preference.Preference)76 PendingIntent (android.app.PendingIntent)73 NotificationChannelGroup (android.app.NotificationChannelGroup)54 NotificationCompat (android.support.v4.app.NotificationCompat)45 Notification (android.app.Notification)43 ArrayList (java.util.ArrayList)34 TargetApi (android.annotation.TargetApi)32 AudioAttributes (android.media.AudioAttributes)31 RequiresApi (android.support.annotation.RequiresApi)28 RequiresApi (androidx.annotation.RequiresApi)25 Uri (android.net.Uri)21 RestrictedListPreference (com.android.settings.RestrictedListPreference)20 SuppressLint (android.annotation.SuppressLint)19 ShortcutInfo (android.content.pm.ShortcutInfo)19