List of usage examples for android.app Notification DEFAULT_ALL
int DEFAULT_ALL
To view the source code for android.app Notification DEFAULT_ALL.
Click Source Link
From source file:com.sonetel.service.SipNotifications.java
public void showNotificationForVoiceMail(SipProfile acc, int numberOfMessages) { if (messageVoicemail == null) { messageVoicemail = new NotificationCompat.Builder(context); messageVoicemail.setSmallIcon(android.R.drawable.stat_notify_voicemail); messageVoicemail.setTicker(context.getString(R.string.voice_mail)); messageVoicemail.setWhen(System.currentTimeMillis()); messageVoicemail.setDefaults(Notification.DEFAULT_ALL); messageVoicemail.setAutoCancel(true); messageVoicemail.setOnlyAlertOnce(true); }/*from ww w. ja v a 2 s . c om*/ PendingIntent contentIntent = null; Intent notificationIntent; if (acc != null && !TextUtils.isEmpty(acc.vm_nbr) && acc.vm_nbr != "null") { notificationIntent = new Intent(Intent.ACTION_CALL); notificationIntent.setData( SipUri.forgeSipUri(SipManager.PROTOCOL_CSIP, acc.vm_nbr + "@" + acc.getDefaultDomain())); notificationIntent.putExtra(SipProfile.FIELD_ACC_ID, acc.id); } else { notificationIntent = new Intent(SipManager.ACTION_SIP_DIALER); } notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); String messageText = ""; if (acc != null) { messageText += acc.getProfileName() + " : "; } messageText += Integer.toString(numberOfMessages); messageVoicemail.setContentTitle(context.getString(R.string.voice_mail)); messageVoicemail.setContentText(messageText); if (contentIntent != null) { messageVoicemail.setContentIntent(contentIntent); notificationManager.notify(VOICEMAIL_NOTIF_ID, messageVoicemail.getNotification()); } }
From source file:com.mattprecious.notisync.service.SecondaryService.java
private void handleCustomMessage(CustomMessage message) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); if (message.packageName.equals("com.whatsapp")) { builder.setSmallIcon(R.drawable.package_com_whatsapp); } else if (message.appName.contains("Gmail")) { builder.setSmallIcon(R.drawable.package_com_google_android_gm); } else {/* ww w. j a v a 2 s. c om*/ builder.setSmallIcon(R.drawable.ic_stat_logo); } builder.setContentTitle(message.messageTitle); builder.setContentText(message.message); builder.setAutoCancel(true); SecondaryProfile profile = null; if (message.tag != null) { dbAdapter.openReadable(); profile = dbAdapter.getSecondaryProfileByTag(message.tag); dbAdapter.close(); if (profile != null) { if (!profile.isEnabled()) { return; } if (profile.isUnconnectedOnly()) { if (isNetworkAvailable()) { return; } } int defaults = 0; if (profile.isVibrate()) { defaults |= Notification.DEFAULT_VIBRATE; } if (profile.isLed()) { defaults |= Notification.DEFAULT_LIGHTS; } //builder.setContentTitle(profile.getName()); builder.setDefaults(defaults); builder.setSound(getRingtoneUri(profile.getRingtone())); openNotificationDatabaseWrite(); notificationsDbAdapter.insertNotification(message.packageName, message.tag, message.appName, message.messageTitle, message.message, message.time); notificationsDbAdapter.close(); } } if (profile == null) { builder.setDefaults(Notification.DEFAULT_ALL); } Intent showIntent = new Intent(this, NotificationListActivity.class); PendingIntent intent = PendingIntent.getActivity(this, 0, showIntent, 0); builder.setContentIntent(intent); Notification notification = new NotificationCompat.BigTextStyle(builder) //.bigText(message.messageTitle) .bigText(message.message).build(); // use the profile ID to determine the notification ID // TODO: note that if somehow a profile ID is ~2^32, we're overwriting // notifications... int notificationId = NOTIFICATION_ID_CUSTOM; if (profile != null) { notificationId += profile.getId(); } notificationManager.notify(notificationId, notification); }
From source file:com.roamprocess1.roaming4world.service.SipNotifications.java
public void showNotificationForVoiceMail(SipProfile acc, int numberOfMessages) { if (messageVoicemail == null) { messageVoicemail = new NotificationCompat.Builder(context); messageVoicemail.setSmallIcon(android.R.drawable.stat_notify_voicemail); messageVoicemail.setTicker(context.getString(R.string.voice_mail)); messageVoicemail.setWhen(System.currentTimeMillis()); messageVoicemail.setDefaults(Notification.DEFAULT_ALL); messageVoicemail.setAutoCancel(true); messageVoicemail.setOnlyAlertOnce(true); }//from w w w. j a va 2s . co m PendingIntent contentIntent = null; Intent notificationIntent; if (acc != null && !TextUtils.isEmpty(acc.vm_nbr) && acc.vm_nbr != "null") { notificationIntent = new Intent(Intent.ACTION_CALL); notificationIntent.setData( SipUri.forgeSipUri(SipManager.PROTOCOL_CSIP, acc.vm_nbr + "@" + acc.getDefaultDomain())); notificationIntent.putExtra(SipProfile.FIELD_ACC_ID, acc.id); } else { notificationIntent = new Intent(SipManager.ACTION_SIP_DIALER); } notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); String messageText = ""; if (acc != null) { messageText += acc.getProfileName() + " : "; } messageText += Integer.toString(numberOfMessages); messageVoicemail.setContentTitle(context.getString(R.string.voice_mail)); System.out.println("SipNotifications messageText " + messageText); messageVoicemail.setContentText(messageText); if (contentIntent != null) { messageVoicemail.setContentIntent(contentIntent); notificationManager.notify(VOICEMAIL_NOTIF_ID, messageVoicemail.build()); } }
From source file:com.z3r0byte.magistify.Services.BackgroundService.java
private void newGradeNotification() { if (!allowDataTransfer()) { return;/*from ww w . j av a 2 s. c o 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.aware.Aware.java
/** * Starts a plugin. Expects the package name of the plugin.<br/> * It checks if the plugin does exist on the phone. If it doesn't, it will request the user to install it automatically. * @param context//w w w . j ava2 s . c o m * @param package_name */ public static void startPlugin(Context context, String package_name) { //Check if plugin is installed. If not, ask user to download it. Cursor is_installed = context.getContentResolver().query(Aware_Plugins.CONTENT_URI, null, Aware_Plugins.PLUGIN_PACKAGE_NAME + " LIKE '" + package_name + "'", null, null); if (is_installed != null && is_installed.moveToFirst()) { //We might just have it cached, but not installed if (isClassAvailable(context, package_name, "Plugin")) { //it's installed, start it! Intent plugin = new Intent(); plugin.setClassName(package_name, package_name + ".Plugin"); context.startService(plugin); if (Aware.DEBUG) Log.d(TAG, package_name + " started..."); ContentValues rowData = new ContentValues(); rowData.put(Aware_Plugins.PLUGIN_STATUS, Aware_Plugin.STATUS_PLUGIN_ON); context.getContentResolver().update(Aware_Plugins.CONTENT_URI, rowData, Aware_Plugins.PLUGIN_PACKAGE_NAME + " LIKE '" + package_name + "'", null); is_installed.close(); return; } is_installed.close(); } HttpResponse response = new Https(awareContext) .dataGET("https://api.awareframework.com/index.php/plugins/get_plugin/" + package_name); if (response != null && response.getStatusLine().getStatusCode() == 200) { try { String data = EntityUtils.toString(response.getEntity()); if (data.equals("[]")) return; JSONObject json_package = new JSONObject(data); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setSmallIcon(R.drawable.ic_stat_aware_plugin_dependency); mBuilder.setContentTitle("AWARE"); mBuilder.setContentText("Plugin missing: " + json_package.getString("title") + ". Tap to install."); mBuilder.setDefaults(Notification.DEFAULT_ALL); mBuilder.setAutoCancel(true); Intent pluginIntent = new Intent(context, DownloadPluginService.class); pluginIntent.putExtra("package_name", package_name); pluginIntent.putExtra("is_update", false); PendingIntent clickIntent = PendingIntent.getService(context, 0, pluginIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(clickIntent); NotificationManager notManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notManager.notify(json_package.getInt("id"), mBuilder.build()); } catch (ParseException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.z3r0byte.magistify.Services.OldBackgroundService.java
private void scheduleChangeTimer() { Log.d(TAG, "scheduleChangeTimer: Starting background service..."); TimerTask scheduleChangeTask = new TimerTask() { @Override/*from ww w. j av a 2 s. com*/ public void run() { if (!allowDataTransfer()) { return; } else { Magister magister = GlobalAccount.MAGISTER; if (magister == null || magister.isExpired()) { Log.d(TAG, "ScheduleChangeNotification: No valid Magister"); } else { ScheduleChangeDB scheduleChangeDB = new ScheduleChangeDB(getApplicationContext()); 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(); Bundle bundle = new Bundle(); bundle.putString(FirebaseAnalytics.Param.ORIGIN, "scheduleChangeTimer"); bundle.putString("error", e.getMessage()); bundle.putString("stacktrace", e.getMessage()); mFirebaseAnalytics.logEvent("error_in_background_schedule", bundle); return; } Boolean newChanges = false; if (appointments == null || appointments.length < 1) { return; } else { Log.d(TAG, "ScheduleChangeNotification: Checking for new changes...."); newChanges = false; for (Appointment appointment : appointments) { if (!scheduleChangeDB.isInDatabase(appointment)) { newChanges = true; } } scheduleChangeDB.addItems(appointments); } if (newChanges) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( getApplicationContext()); 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(getApplicationContext(), ScheduleChangeActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext()); stackBuilder.addParentStack(ScheduleChangeActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(9993, mBuilder.build()); } } } } }; timer.schedule(scheduleChangeTask, 6000, 120 * 1000); }
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 {//w w w .j a v a 2s . c om 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.OldBackgroundService.java
private void notifyAppointmentChangedTimer() { Log.d(TAG, "notifyAppoinytmentTimer: Starting notify appointmentchange timer"); TimerTask notificationTask = new TimerTask() { @Override/*from w w w . ja v a 2 s . c om*/ public void run() { ScheduleChangeDB scheduleChangeDB = new ScheduleChangeDB(getApplicationContext()); Appointment[] appointments = scheduleChangeDB.getNotificationAppointments(); previousChangedAppointment = configUtil.getString("previous_changed_appointment"); if (appointments.length > 0) { Appointment appointment = appointments[0]; if (!appointment.startDateString.equals(previousChangedAppointment)) { String content; if (appointment.description != null && !appointment.description.equalsIgnoreCase("null")) { content = appointment.description; } else { content = "De les is uitgevallen!"; } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( getApplicationContext()); 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(getApplicationContext(), ScheduleChangeActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext()); stackBuilder.addParentStack(ScheduleChangeActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(9994, mBuilder.build()); previousChangedAppointment = appointment.startDateString; configUtil.setString("previous_changed_appointment", appointment.startDateString); } } else { NotificationManager notifManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notifManager.cancel(9994); } } }; timer.schedule(notificationTask, 20000, 30 * 1000); }
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;//from www . j a v a 2 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); } }
From source file:com.z3r0byte.magistify.Services.BackgroundService.java
private void newHomeworkNotification() { Appointment[] newhomework = homeworkDB.getAppointmentsWithHomework(); ArrayList<Appointment> homeworkList = new ArrayList<>(); for (Appointment appointment : newhomework) { if (homeworkDB.isModified(appointment, true)) homeworkList.add(appointment); }// w ww. j av a 2s .c o m Log.d(TAG, "newHomeworkNotification: Amount of new homework: " + homeworkList.size()); if (homeworkList.size() > 0) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setSmallIcon(R.drawable.ic_new_homework); String content = "Je hebt nieuw of aangepast huiswerk voor:"; for (Appointment appointment : homeworkList) { content = content + "\n" + appointment.description + DateUtils.formatDate(appointment.startDate, "' ('dd MMM')'"); } mBuilder.setContentTitle("Nieuw huiswerk"); mBuilder.setStyle(new NotificationCompat.BigTextStyle(mBuilder).bigText(content)); mBuilder.setContentText(content); mBuilder.setAutoCancel(true); mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); mBuilder.setDefaults(Notification.DEFAULT_ALL); Intent resultIntent = new Intent(context, HomeworkActivity.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_HOMEWORK_NOTIFICATIONCHANNEL_ID; CharSequence channelName = NEW_HOMEWORK_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_HOMEWORK_NOTIFICATIONCHANNEL_ID); } mNotificationManager.notify(NEW_HOMEWORK_NOTIFICATION_ID, mBuilder.build()); } }