List of usage examples for android.app NotificationManager createNotificationChannel
public void createNotificationChannel(@NonNull NotificationChannel channel)
From source file:com.ruesga.rview.misc.NotificationsHelper.java
@TargetApi(Build.VERSION_CODES.O) public static void createNotificationChannel(Context context, Account account) { if (AndroidHelper.isApi26OrGreater()) { final String defaultChannelName = context.getString(R.string.notifications_default_channel_name, account.getRepositoryDisplayName(), account.getAccountDisplayName()); final NotificationManager nm = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); nm.createNotificationChannelGroup( new NotificationChannelGroup(account.getAccountHash(), defaultChannelName)); NotificationChannel channel = new NotificationChannel(account.getAccountHash(), defaultChannelName, NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription(context.getString(R.string.notifications_default_channel_description)); channel.enableVibration(true);// w w w .ja v a2s.c o m channel.enableLights(true); channel.setLightColor(ContextCompat.getColor(context, R.color.primaryDark)); channel.setShowBadge(true); channel.setGroup(account.getAccountHash()); nm.createNotificationChannel(channel); } }
From source file:androidx.navigation.testapp.AndroidFragment.java
@Override public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); TextView tv = view.findViewById(R.id.text); tv.setText(getArguments().getString("myarg")); Button b = view.findViewById(R.id.send_notification); b.setOnClickListener(new View.OnClickListener() { @Override/*from w ww . j a v a 2s .c o m*/ public void onClick(View v) { EditText editArgs = view.findViewById(R.id.edit_args); Bundle args = new Bundle(); args.putString("myarg", editArgs.getText().toString()); PendingIntent deeplink = Navigation.findNavController(v).createDeepLink() .setDestination(R.id.android).setArguments(args).createPendingIntent(); NotificationManager notificationManager = (NotificationManager) requireContext() .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { notificationManager.createNotificationChannel( new NotificationChannel("deeplink", "Deep Links", NotificationManager.IMPORTANCE_HIGH)); } NotificationCompat.Builder builder = new NotificationCompat.Builder(requireContext(), "deeplink") .setContentTitle("Navigation").setContentText("Deep link to Android") .setSmallIcon(R.drawable.ic_android).setContentIntent(deeplink).setAutoCancel(true); notificationManager.notify(0, builder.build()); } }); }
From source file:com.commonsware.android.bluetooth.rxecho.ShoutingEchoService.java
@Override public void onCreate() { super.onCreate(); rxBluetooth = new RxBluetooth(getApplicationContext()); acceptConnections();/*w ww. j av a 2s .c om*/ NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && mgr.getNotificationChannel(CHANNEL_WHATEVER) == null) { mgr.createNotificationChannel( new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT)); } startForeground(1338, buildForegroundNotification()); STATUS.postValue(Status.IS_RUNNING); }
From source file:com.giovanniterlingen.windesheim.controllers.NotificationController.java
public void initNotificationChannels() { if (android.os.Build.VERSION.SDK_INT >= 26) { NotificationChannel pushChannel = new NotificationChannel(PUSH_NOTIFICATION_CHANNEL, ApplicationLoader.applicationContext.getResources().getString(R.string.push_notification), NotificationManager.IMPORTANCE_HIGH); pushChannel.setDescription(ApplicationLoader.applicationContext.getResources() .getString(R.string.push_notification_description)); pushChannel.enableLights(true);// ww w . j a v a 2 s .c o m pushChannel.enableVibration(true); pushChannel.setShowBadge(true); pushChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); NotificationChannel persistentChannel = new NotificationChannel(PERSISTENT_NOTIFICATION_CHANNEL, ApplicationLoader.applicationContext.getResources().getString(R.string.persistent_notification), NotificationManager.IMPORTANCE_MIN); persistentChannel.setDescription(ApplicationLoader.applicationContext.getResources() .getString(R.string.persistent_notification_description)); persistentChannel.enableLights(false); persistentChannel.enableVibration(false); persistentChannel.setShowBadge(false); persistentChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); NotificationChannel serviceChannel = new NotificationChannel(SERVICE_NOTIFICATION_CHANNEL, ApplicationLoader.applicationContext.getResources().getString(R.string.service_notification), NotificationManager.IMPORTANCE_MIN); serviceChannel.setDescription(ApplicationLoader.applicationContext.getResources() .getString(R.string.service_notification_description)); serviceChannel.enableLights(false); serviceChannel.enableVibration(false); serviceChannel.setShowBadge(false); serviceChannel.setLockscreenVisibility(Notification.VISIBILITY_SECRET); NotificationManager mManager = (NotificationManager) ApplicationLoader.applicationContext .getSystemService(Context.NOTIFICATION_SERVICE); mManager.createNotificationChannel(pushChannel); mManager.createNotificationChannel(persistentChannel); mManager.createNotificationChannel(serviceChannel); } }
From source file:arun.com.chromer.appdetect.AppDetectService.java
private void initChannels() { if (Utils.ANDROID_OREO) { NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "App Detection Service", NotificationManager.IMPORTANCE_MIN); channel.setDescription(getString(R.string.app_detection_notification_channel_description)); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.createNotificationChannel(channel); }/* ww w . ja v a 2s . c om*/ }
From source file:de.aw.awlib.AWNotification.java
/** * Cancelt die Notification//from w w w. ja v a2 s.c om */ public void cancel() { String ns = Context.NOTIFICATION_SERVICE; NotificationManager nMgr = (NotificationManager) context.getSystemService(ns); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { nMgr.createNotificationChannel(mNotificationChannel); } nMgr.cancel(mNotifyID); }
From source file:de.aw.awlib.AWNotification.java
/** * Erstellt Notification mit neuem Titel und neuen Text * * @param contentTitle ContentTitel/*from ww w. ja v a 2s .c o m*/ * @param contentText ContentText * @return NotifyID */ public int createNotification(@NonNull String contentTitle, @NonNull String contentText) { NotificationCompat.Builder mBuilder = getNotification(); mBuilder.setContentTitle(contentTitle); mBuilder.setContentText(contentText); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { mNotificationManager.createNotificationChannel(mNotificationChannel); } mNotificationManager.notify(mNotifyID, mBuilder.build()); return mNotifyID; }
From source file:de.aw.awlib.AWNotification.java
/** * Notification mit nur einer Zeile.//from w w w . j a v a 2 s . c o m * * @param contentTitle Title der Notification * @param contentText Text der Notification * @return NotifyID */ public int replaceNotification(@NonNull String contentTitle, @NonNull String contentText) { NotificationCompat.Builder mBuilder = getNotification(); mBuilder.setContentTitle(contentTitle); mBuilder.setContentText(contentText); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { mNotificationManager.createNotificationChannel(mNotificationChannel); } mNotificationManager.notify(mNotifyID, mBuilder.build()); return mNotifyID; }
From source file:de.aw.awlib.AWNotification.java
/** * Ersetze Notification./*from w w w .j a v a 2s .c om*/ * * @param contentListHeader Header der Liste. * @param contentListTexte Liste der NotificationTexte * @return die NotificationID */ public int replaceNotification(@NonNull String contentListHeader, @NonNull List<String> contentListTexte) { NotificationCompat.Builder mBuilder = getNotification(); mBuilder.setContentTitle(contentTitle); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setSummaryText(contentListHeader); for (String s : contentListTexte) { inboxStyle.addLine(s); } mBuilder.setContentText(contentListHeader); mBuilder.setStyle(inboxStyle); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { mNotificationManager.createNotificationChannel(mNotificationChannel); } mNotificationManager.notify(mNotifyID, mBuilder.build()); return mNotifyID; }
From source file:de.aw.awlib.AWNotification.java
/** * Erstelle Notification./*from www . ja va2 s. co m*/ * * @param contentListHeader Header der Liste. * @param contentListTexte Liste der NotificationTexte * @return die NotificationID */ public int createNotification(@NonNull String contentListHeader, @NonNull List<String> contentListTexte) { NotificationCompat.Builder mBuilder = getNotification(); mBuilder.setContentTitle(contentTitle); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setSummaryText(contentListHeader); for (String s : contentListTexte) { inboxStyle.addLine(s); } mBuilder.setContentText(contentListHeader); mBuilder.setStyle(inboxStyle); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { mNotificationManager.createNotificationChannel(mNotificationChannel); } mNotificationManager.notify(mNotifyID, mBuilder.build()); return mNotifyID; }