List of usage examples for android.app NotificationManager IMPORTANCE_LOW
int IMPORTANCE_LOW
To view the source code for android.app NotificationManager IMPORTANCE_LOW.
Click Source Link
From source file:com.z3r0byte.magistify.Services.BackgroundService.java
private void manageSession(final User user, final School school) { if (allowDataTransfer()) { if (GlobalAccount.MAGISTER == null) { if (configUtil.getInteger("failed_auth") >= 2) { Log.w(TAG, "run: Warning! 2 Failed authentications, aborting for user's safety!"); if (configUtil.getBoolean("shown_failed_login_notification")) return; configUtil.setBoolean("shown_failed_login_notification", true); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setSmallIcon(R.drawable.ic_error); Intent resultIntent = new Intent(context, DashboardActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(DashboardActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setContentTitle(context.getString(R.string.dialog_login_failed_title)); mBuilder.setContentText(context.getString(R.string.msg_fix_login)); mBuilder.setAutoCancel(true); mBuilder.setSound(null); mBuilder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= 26) { String channelId = LOGIN_FAILED_CHANNEL_ID; CharSequence channelName = LOGIN_FAILED_CHANNEL_ID; int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance); notificationChannel.enableLights(true); notificationChannel.setLightColor(Color.RED); notificationChannel.enableVibration(true); notificationChannel.setImportance(NotificationManager.IMPORTANCE_DEFAULT); notificationChannel.setVibrationPattern(new long[] { 100, 200, 150 }); mNotificationManager.createNotificationChannel(notificationChannel); mBuilder.setChannelId(LOGIN_FAILED_CHANNEL_ID); }/*from w w w . j a va2 s .com*/ mNotificationManager.notify(LOGIN_FAILED_ID, mBuilder.build()); } else { configUtil.setBoolean("shown_failed_login_notification", false); try { Log.d(TAG, "SessionManager: initiating session"); GlobalAccount.MAGISTER = Magister.login(school, user.username, user.password); configUtil.setInteger("failed_auth", 0); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (InvalidParameterException e) { int fails = configUtil.getInteger("failed_auth"); fails++; configUtil.setInteger("failed_auth", fails); Log.w(TAG, "SessionManager: Amount of failed Authentications: " + fails); } } } else if (GlobalAccount.MAGISTER.isExpired()) { configUtil.setBoolean("shown_failed_login_notification", false); try { GlobalAccount.MAGISTER.login(); Log.d(TAG, "SessionManager: refreshing session"); configUtil.setInteger("failed_auth", 0); } catch (IOException e) { e.printStackTrace(); } catch (InvalidParameterException e) { e.printStackTrace(); int fails = configUtil.getInteger("failed_auth"); fails++; configUtil.setInteger("failed_auth", fails); Log.w(TAG, "SessionManager: Amount of failed Authentications: " + fails); } } else { Log.d(TAG, "manageSession: Session still valid"); } } }
From source file:com.owncloud.android.media.MediaService.java
/** * Initialize a service instance/*w w w . j av a 2 s . co m*/ * * {@inheritDoc} */ @Override public void onCreate() { super.onCreate(); Log_OC.d(TAG, "Creating ownCloud media service"); mWifiLock = ((WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, MEDIA_WIFI_LOCK_TAG); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Configure notification channel if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel mNotificationChannel; // The user-visible name of the channel. CharSequence name = getString(R.string.media_service_notification_channel_name); // The user-visible description of the channel. String description = getString(R.string.media_service_notification_channel_description); // Set importance low: show the notification everywhere but with no sound int importance = NotificationManager.IMPORTANCE_LOW; mNotificationChannel = new NotificationChannel(MEDIA_SERVICE_NOTIFICATION_CHANNEL_ID, name, importance); // Configure the notification channel. mNotificationChannel.setDescription(description); mNotificationManager.createNotificationChannel(mNotificationChannel); } mNotificationBuilder = new NotificationCompat.Builder(this); mNotificationBuilder.setColor(this.getResources().getColor(R.color.primary)); mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); mBinder = new MediaServiceBinder(this); // add AccountsUpdatedListener mAccountManager = AccountManager.get(this); mAccountManager.addOnAccountsUpdatedListener(new OnAccountsUpdateListener() { @Override public void onAccountsUpdated(Account[] accounts) { // stop playback if account of the played media files was removed if (mAccount != null && !AccountUtils.exists(mAccount.name, MediaService.this)) { processStopRequest(false); } } }, null, false); }
From source file:com.z3r0byte.magistify.Services.BackgroundService.java
private void appointmentNotification() { Appointment[] appointments = calendarDB.getNotificationAppointments(); Log.d(TAG, "AppointmentNotifications: amount of appointments that should be shown: " + appointments.length); String previousAppointment = configUtil.getString("previous_appointment"); if (appointments.length >= 1) { Appointment appointment = appointments[0]; if (!mGson.toJson(appointment).equals(previousAppointment) && isCandidate(appointment)) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setSmallIcon(R.drawable.ic_appointment); if (appointment.startDate != null) { String time = DateUtils.formatDate(appointment.startDate, "HH:mm"); mBuilder.setContentTitle("Volgende afspraak (" + time + ")"); } else { mBuilder.setContentTitle("Volgende afspraak:"); }// w w w. j ava 2 s . c o m mBuilder.setContentText(appointment.description + " in " + appointment.location); mBuilder.setAutoCancel(true); mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); Intent resultIntent = new Intent(context, AppointmentActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(AppointmentActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= 26) { String channelId = APPOINTMENT_NOTIFICATIONCHANNEL_ID; CharSequence channelName = APPOINTMENT_NOTIFICATIONCHANNEL_ID; int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance); notificationChannel.enableLights(false); notificationChannel.enableVibration(false); notificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); mNotificationManager.createNotificationChannel(notificationChannel); mBuilder.setChannelId(APPOINTMENT_NOTIFICATIONCHANNEL_ID); } mNotificationManager.notify(APPOINTMENT_NOTIFICATION_ID, mBuilder.build()); previousAppointment = mGson.toJson(appointment); configUtil.setString("previous_appointment", previousAppointment); } } else { NotificationManager notifManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notifManager.cancel(APPOINTMENT_NOTIFICATION_ID); } }
From source file:github.popeen.dsub.util.Notifications.java
@TargetApi(Build.VERSION_CODES.O) private static NotificationChannel getPlayingNotificationChannel(Context context) { if (playingChannel == null) { playingChannel = new NotificationChannel("now-playing-channel", "Now Playing", NotificationManager.IMPORTANCE_LOW); playingChannel.setDescription("Now playing notification"); NotificationManager notificationManager = context.getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(playingChannel); }//w w w. ja v a 2 s . com return playingChannel; }
From source file:com.scooter1556.sms.android.manager.MediaNotificationManager.java
/** * Creates Notification Channel. This is required in Android O+ to display notifications. *//* w ww. j ava 2 s . com*/ private void createNotificationChannel() { if (notificationManager.getNotificationChannel(CHANNEL_ID) == null) { NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, mediaService.getString(R.string.notification_channel), NotificationManager.IMPORTANCE_LOW); notificationChannel.setDescription(mediaService.getString(R.string.notification_channel_description)); notificationManager.createNotificationChannel(notificationChannel); } }
From source file:github.popeen.dsub.util.Notifications.java
@TargetApi(Build.VERSION_CODES.O) private static NotificationChannel getDownloadingNotificationChannel(Context context) { if (downloadingChannel == null) { downloadingChannel = new NotificationChannel("downloading-channel", "Downloading Notification", NotificationManager.IMPORTANCE_LOW); downloadingChannel.setDescription("Ongoing downloading notification to keep the service alive"); NotificationManager notificationManager = context.getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(downloadingChannel); }// w w w .j av a 2s . c om return downloadingChannel; }
From source file:org.pocketworkstation.pckeyboard.LatinIME.java
private void createNotificationChannel() { // Create the NotificationChannel, but only on API 26+ because // the NotificationChannel class is new and not in the support library if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { CharSequence name = getString(R.string.notification_channel_name); String description = getString(R.string.notification_channel_description); int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance); channel.setDescription(description); // Register the channel with the system; you can't change the importance // or other notification behaviors after this NotificationManager notificationManager = getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel); }//w w w . j a v a2s .co m }
From source file:com.z3r0byte.magistify.Services.BackgroundService.java
private void newGradeNotification() { if (!allowDataTransfer()) { return;/*from w w w. ja va 2s .co m*/ } Magister magister = GlobalAccount.MAGISTER; if (magister == null || magister.isExpired()) { Log.e(TAG, "New Grade Notification: Invalid magister"); } else { GradeHandler gradeHandler = new GradeHandler(magister); Grade[] gradeArray; List<Grade> gradeList = new ArrayList<Grade>(); try { gradeArray = gradeHandler.getRecentGrades(); gradesdb.addGrades(gradeArray); Collections.reverse(Arrays.asList(gradeArray)); //For testing purposes: /*Grade sampleGrade = new Grade(); sampleGrade.isSufficient = false; sampleGrade.grade = "2.3"; sampleGrade.subject = new SubSubject(); sampleGrade.subject.name = "Latijn"; Grade sampleGrade2 = new Grade(); sampleGrade2.isSufficient = true; sampleGrade2.grade = "6.5"; sampleGrade2.subject = new SubSubject(); sampleGrade2.subject.name = "Nederlands"; gradeArray = new Grade[2]; gradeArray[0] = sampleGrade; gradeArray[1] = sampleGrade2;*/ for (Grade grade : gradeArray) { if (!gradesdb.hasBeenSeen(grade, false) && (grade.isSufficient || !configUtil.getBoolean("pass_grades_only"))) { gradeList.add(grade); } } } catch (IOException | AssertionError | NullPointerException e) { e.printStackTrace(); return; } String GradesNotification = mGson.toJson(gradeList); if (gradeList.size() > 0 && !configUtil.getString("lastGradesNotification").equals(GradesNotification)) { Log.d(TAG, "New Grade Notification: Some grades to show: " + gradeList.size()); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setSmallIcon(R.drawable.ic_grade_notification); if (gradeList.size() == 1) { Grade grade = gradeList.get(0); if (grade.description != null) { mBuilder.setContentTitle( "Nieuw cijfer voor " + grade.subject.name + " - " + grade.description); } else { mBuilder.setContentTitle("Nieuw cijfer voor " + grade.subject.name); } //mBuilder.setStyle(new NotificationCompat.BigTextStyle(mBuilder).bigText()) mBuilder.setContentText("Een " + grade.grade); } else { CharSequence content = ""; for (Grade grade : gradeList) { CharSequence string; if (grade.description != null) { string = grade.subject.name + " - " + grade.description + ": " + Html.fromHtml("<strong>" + grade.grade + "</strong>"); } else { string = grade.subject.name + ", een " + grade.grade; } if (content.length() > 1) { content = content + "\n" + string; } else { content = string; } } mBuilder.setContentTitle("Nieuwe cijfers voor:"); mBuilder.setStyle(new NotificationCompat.BigTextStyle(mBuilder).bigText(content)); mBuilder.setContentText(content); } mBuilder.setAutoCancel(true); mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); mBuilder.setDefaults(Notification.DEFAULT_ALL); mBuilder.setLights(Color.LTGRAY, 300, 200); Intent resultIntent = new Intent(context, NewGradeActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(NewGradeActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= 26) { String channelId = NEW_GRADE_NOTIFICATIONCHANNEL_ID; CharSequence channelName = NEW_GRADE_NOTIFICATIONCHANNEL_ID; int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance); notificationChannel.enableLights(true); notificationChannel.setLightColor(Color.RED); notificationChannel.enableVibration(true); notificationChannel.setImportance(NotificationManager.IMPORTANCE_DEFAULT); notificationChannel.setVibrationPattern(new long[] { 100, 200, 150 }); mNotificationManager.createNotificationChannel(notificationChannel); mBuilder.setChannelId(NEW_GRADE_NOTIFICATIONCHANNEL_ID); } mNotificationManager.notify(NEW_GRADE_NOTIFICATION_ID, mBuilder.build()); configUtil.setString("lastGradesNotification", GradesNotification); } else { Log.w(TAG, "New Grade Notification: No grades!"); } } }
From source file:com.z3r0byte.magistify.Services.BackgroundService.java
private void newScheduleChangeNotification() { if (allowDataTransfer()) { Magister magister = GlobalAccount.MAGISTER; if (magister == null || magister.isExpired()) { Log.d(TAG, "ScheduleChangeNotification: No valid Magister"); } else {/*from w w w . j av a 2 s . com*/ AppointmentHandler appointmentHandler = new AppointmentHandler(magister); Appointment[] appointments; try { Log.d(TAG, "ScheduleChangeNotification: Requesting schedule changes...."); appointments = appointmentHandler.getScheduleChanges(DateUtils.getToday(), DateUtils.addDays(DateUtils.getToday(), 3)); } catch (IOException | AssertionError e) { Log.d(TAG, "ScheduleChangeNotification: Error while requesting schedule changes"); e.printStackTrace(); return; } Boolean newChanges = false; if (appointments == null || appointments.length < 1) { return; } else { Log.d(TAG, "ScheduleChangeNotification: Checking for new changes...."); for (Appointment appointment : appointments) { if (!scheduleChangeDB.isInDatabase(appointment)) { newChanges = true; } } scheduleChangeDB.addItems(appointments); } if (newChanges) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setSmallIcon(R.drawable.ic_schedule_change); mBuilder.setContentTitle("Nieuwe roosterijziging(en)!"); mBuilder.setContentText("Tik om te bekijken"); mBuilder.setAutoCancel(true); mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); mBuilder.setDefaults(Notification.DEFAULT_ALL); Intent resultIntent = new Intent(context, ScheduleChangeActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(ScheduleChangeActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= 26) { String channelId = NEW_SCHEDULE_CHANGE_NOTIFICATIONCHANNEL_ID; CharSequence channelName = NEW_SCHEDULE_CHANGE_NOTIFICATIONCHANNEL_ID; int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance); notificationChannel.enableLights(true); notificationChannel.setLightColor(Color.RED); notificationChannel.enableVibration(true); notificationChannel.setImportance(NotificationManager.IMPORTANCE_DEFAULT); notificationChannel.setVibrationPattern(new long[] { 100, 200, 150 }); mNotificationManager.createNotificationChannel(notificationChannel); mBuilder.setChannelId(NEW_SCHEDULE_CHANGE_NOTIFICATIONCHANNEL_ID); } mNotificationManager.notify(NEW_SCHEDULE_CHANGE_NOTIFICATION_ID, mBuilder.build()); } } } }
From source file:com.z3r0byte.magistify.Services.BackgroundService.java
private void nextAppointmentChangedNotification() { Appointment[] appointments = scheduleChangeDB.getNotificationAppointments(); String previousChangedAppointment = configUtil.getString("previous_changed_appointment"); if (appointments.length > 0) { Appointment appointment = appointments[0]; if (!appointment.startDateString.equals(previousChangedAppointment)) { String content;/* ww w . j a va2 s . c o m*/ if (appointment.description != null && !appointment.description.equalsIgnoreCase("null")) { content = appointment.description; } else { content = "De les is uitgevallen!"; } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setSmallIcon(R.drawable.ic_schedule_change); mBuilder.setContentTitle("Let op! De volgende les is gewijzigd!"); mBuilder.setContentText(content); mBuilder.setAutoCancel(true); mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); mBuilder.setDefaults(Notification.DEFAULT_ALL); Intent resultIntent = new Intent(context, ScheduleChangeActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(ScheduleChangeActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= 26) { String channelId = NEXT_APPOINTMENT_CHANGED_NOTIFICATIONCHANNEL_ID; CharSequence channelName = NEXT_APPOINTMENT_CHANGED_NOTIFICATIONCHANNEL_ID; int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance); notificationChannel.enableLights(true); notificationChannel.setLightColor(Color.RED); notificationChannel.enableVibration(true); notificationChannel.setImportance(NotificationManager.IMPORTANCE_DEFAULT); notificationChannel.setVibrationPattern(new long[] { 100, 200, 150 }); mNotificationManager.createNotificationChannel(notificationChannel); mBuilder.setChannelId(NEXT_APPOINTMENT_CHANGED_NOTIFICATIONCHANNEL_ID); } mNotificationManager.notify(NEXT_APPOINTMENT_CHANGED_NOTIFICATION_ID, mBuilder.build()); configUtil.setString("previous_changed_appointment", appointment.startDateString); } } else { NotificationManager notifManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notifManager.cancel(NEXT_APPOINTMENT_CHANGED_NOTIFICATION_ID); } }