List of usage examples for android.app Notification.Builder Notification.Builder
@Deprecated
public Builder(Context context)
From source file:info.balthaus.geologrenewed.app.service.BackgroundService.java
@SuppressLint("NewApi") @Override/*from w ww . jav a2 s .c om*/ public void onCreate() { super.onCreate(); Debug.log("Service created"); if (thread == null) { Debug.log("Launching thread"); thread = new ServiceThread(); thread.setContext(getApplicationContext()); thread.start(); } PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "GeoLog Wakelock"); Intent i = new Intent(); i.setAction(Intent.ACTION_MAIN); i.addCategory(Intent.CATEGORY_LAUNCHER); i.setClass(this, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NEW_TASK); notificationIntent = PendingIntent.getActivity(this, 0, i, 0); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationBuilder = (new Notification.Builder(this)).setSmallIcon(R.drawable.ic_stat_service) .setContentIntent(notificationIntent).setWhen(System.currentTimeMillis()).setAutoCancel(false) .setOngoing(true).setContentTitle(getString(R.string.service_title)) .setContentText(getString(R.string.service_waiting)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { notificationBuilder.setShowWhen(false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { /* quick turn off, maybe ? if added, make sure to add a button to preferences to disable these buttons notificationBuilder. setPriority(Notification.PRIORITY_MAX). addAction(0, "A", notificationIntent). addAction(0, "B", notificationIntent). addAction(0, "C", notificationIntent); */ } updateNotification(); }
From source file:com.metinkale.prayerapp.vakit.WidgetService.java
public static void updateOngoing() { extractColors();//from w w w . j a v a 2 s . c om NotificationManager nm = (NotificationManager) App.getContext() .getSystemService(Context.NOTIFICATION_SERVICE); for (int i = mOngoing.size() - 1; i >= 0; i--) { long id = mOngoing.get(i); Times t = Times.getTimes(id); if ((t == null) || !t.isOngoingNotificationActive()) { nm.cancel(id + "", NotIds.ONGOING); mOngoing.remove(i); } } List<Long> ids = Times.getIds(); for (long id : ids) { Times t = Times.getTimes(id); if ((t != null) && t.isOngoingNotificationActive() && !mOngoing.contains(id)) { mOngoing.add(id); } } LocalDate cal = LocalDate.now(); String[] left_part = App.getContext().getResources().getStringArray(R.array.lefttext_part); for (long id : mOngoing) { Times t = Times.getTimes(id); String[] dt = { t.getTime(cal, 0), t.getTime(cal, 1), t.getTime(cal, 2), t.getTime(cal, 3), t.getTime(cal, 4), t.getTime(cal, 5) }; boolean icon = Prefs.showOngoingIcon(); boolean number = Prefs.showOngoingNumber(); Crashlytics.setBool("showIcon", icon); Crashlytics.setBool("showNumber", number); Notification noti; if (Prefs.getAlternativeOngoing()) { RemoteViews views = new RemoteViews(App.getContext().getPackageName(), R.layout.notification_layout); int[] timeIds = { R.id.time0, R.id.time1, R.id.time2, R.id.time3, R.id.time4, R.id.time5 }; int[] vakitIds = { R.id.imsak, R.id.gunes, R.id.ogle, R.id.ikindi, R.id.aksam, R.id.yatsi }; int next = t.getNext(); if (Prefs.getVakitIndicator().equals("next")) next++; for (int i = 0; i < dt.length; i++) { if ((next - 1) == i) { views.setTextViewText(timeIds[i], Html.fromHtml("<strong><em>" + Utils.fixTime(dt[i]) + "</em></strong>")); } else { views.setTextViewText(timeIds[i], Utils.fixTime(dt[i])); } } for (int i = 0; i < dt.length; i++) { if ((next - 1) == i) { views.setTextViewText(vakitIds[i], Html.fromHtml("<strong><em>" + Vakit.getByIndex(i).getString() + "</em></strong>")); } else { views.setTextViewText(vakitIds[i], Vakit.getByIndex(i).getString()); } } views.setTextViewText(R.id.time, t.getLeft(t.getNext(), false)); views.setTextViewText(R.id.city, t.getName()); views.setTextColor(R.id.imsak, COLOR_1ST); views.setTextColor(R.id.gunes, COLOR_1ST); views.setTextColor(R.id.ogle, COLOR_1ST); views.setTextColor(R.id.ikindi, COLOR_1ST); views.setTextColor(R.id.aksam, COLOR_1ST); views.setTextColor(R.id.yatsi, COLOR_1ST); views.setTextColor(R.id.time0, COLOR_1ST); views.setTextColor(R.id.time1, COLOR_1ST); views.setTextColor(R.id.time2, COLOR_1ST); views.setTextColor(R.id.time3, COLOR_1ST); views.setTextColor(R.id.time4, COLOR_1ST); views.setTextColor(R.id.time5, COLOR_1ST); views.setTextColor(R.id.time, COLOR_1ST); views.setTextColor(R.id.city, COLOR_1ST); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { long left = t.getLeftMinutes(t.getNext()); noti = new Notification.Builder(App.getContext()).setContent(views) .setContentIntent(Main.getPendingIntent(t)) .setSmallIcon(icon ? (number ? Icon.createWithBitmap(getIconFromMinutes(left)) : Icon.createWithResource(App.getContext(), R.drawable.ic_abicon)) : Icon.createWithResource(App.getContext(), R.drawable.ic_placeholder)) .setOngoing(true).build(); } else { noti = new NotificationCompat.Builder(App.getContext()).setContent(views) .setContentIntent(Main.getPendingIntent(t)) .setSmallIcon(icon ? R.drawable.ic_abicon : R.drawable.ic_placeholder).setOngoing(true) .build(); } } else { int n = t.getNext(); String sum = App.getContext().getString(R.string.leftText, Vakit.getByIndex(n - 1).getString(), left_part[n], t.getLeft().substring(0, 5)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { long left = t.getLeftMinutes(t.getNext()); noti = new Notification.InboxStyle( new Notification.Builder(App.getContext()) .setContentTitle(t.getName() + " (" + t.getSource() + ")").setContentText("") .setLargeIcon(mAbIcon) .setSmallIcon(icon ? (number ? Icon.createWithBitmap(getIconFromMinutes(left)) : Icon.createWithResource(App.getContext(), R.drawable.ic_abicon)) : Icon.createWithResource(App.getContext(), R.drawable.ic_placeholder)) .setContentInfo(sum).setContentIntent(Main.getPendingIntent(t)) .setOngoing(true)) .addLine(Vakit.getByIndex(0).getString() + ": " + Utils.fixTime(dt[0])) .addLine(Vakit.GUNES.getString() + ": " + Utils.fixTime(dt[1])) .addLine(Vakit.OGLE.getString() + ": " + Utils.fixTime(dt[2])) .addLine(Vakit.IKINDI.getString() + ": " + Utils.fixTime(dt[3])) .addLine(Vakit.AKSAM.getString() + ": " + Utils.fixTime(dt[4])) .addLine(Vakit.YATSI.getString() + ": " + Utils.fixTime(dt[5])) .setSummaryText("").build(); } else { noti = new NotificationCompat.InboxStyle(new NotificationCompat.Builder(App.getContext()) .setContentTitle(t.getName() + " (" + t.getSource() + ")").setContentText("") .setLargeIcon(mAbIcon) .setSmallIcon(icon ? R.drawable.ic_abicon : R.drawable.ic_placeholder) .setContentInfo(sum).setContentIntent(Main.getPendingIntent(t)).setOngoing(true)) .addLine(Vakit.getByIndex(0).getString() + ": " + Utils.fixTime(dt[0])) .addLine(Vakit.GUNES.getString() + ": " + Utils.fixTime(dt[1])) .addLine(Vakit.OGLE.getString() + ": " + Utils.fixTime(dt[2])) .addLine(Vakit.IKINDI.getString() + ": " + Utils.fixTime(dt[3])) .addLine(Vakit.AKSAM.getString() + ": " + Utils.fixTime(dt[4])) .addLine(Vakit.YATSI.getString() + ": " + Utils.fixTime(dt[5])) .setSummaryText("").build(); } } if (Build.VERSION.SDK_INT >= 16) { noti.priority = Notification.PRIORITY_LOW; } noti.when = icon ? System.currentTimeMillis() : 0; try { nm.notify(id + "", NotIds.ONGOING, noti); } catch (Exception e) { Crashlytics.logException(e); } } }
From source file:com.eggwall.AdkUnoUsbHostExample.control.AccessoryService.java
/** * The idea here is to set the notification so that the service can always run. However, ths is not * happening correctly right now.//from www . ja va2 s .c o m */ private void setForegroundService() { final Intent showClock = new Intent(this, AccessoryActivity.class); final PendingIntent pending = PendingIntent.getActivity(this, 0, showClock, PendingIntent.FLAG_UPDATE_CURRENT); // Show the circuit board icon and the ADK name. final int icon = R.drawable.ic_launcher; final String title = "AdkSample"; final Notification n; if (SDK >= 11) { // TODO: Set an icon that is the input and output conjoined final Notification.Builder builder = new Notification.Builder(this).setContentTitle(title) .setSmallIcon(icon).setOngoing(true); builder.setContentIntent(pending); n = builder.build(); } else { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentTitle(title) .setSmallIcon(icon).setOngoing(true); builder.setContentIntent(pending); n = builder.build(); } Log.d(TAG, "Starting foreground"); startForeground(NOTIFICATION_ID, n); }
From source file:android.app.Activity.java
/** * @hide//w w w .ja v a 2 s . c om */ private void showMigrateNotification() { boolean flag = false; if (mMigrator == null) { mMigrator = IMigratorService.Stub.asInterface(ServiceManager.getService("Migrator")); } try { /* judge whether this App can migrate */ flag = mMigrator.checkMigratableApp(); } catch (RemoteException e) { Log.d(TAG, "Migrate failed in Dialog"); } if (flag) { Intent intent = new Intent(); intent.setClassName("com.android.migrationmanager", "com.android.migrationmanager.DeviceListDialog"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); /* on tapping, show dialog Activity */ Notification notification = new Notification.Builder(this) .setContentTitle("Migrator in " + getAppName()) .setContentText("start Migration: " + getLocalClassName()) .setSmallIcon(com.android.internal.R.drawable.ic_menu_send).setAutoCancel(true) .setContentIntent(pi).build(); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(Process.myUid(), notification); } }