@Override public void vaddLogNotif(final Context ctxt, final boolean flag) { if (!flag) { vcancel(ctxt, LOG_TAG, NotifUtil.LOGNOTIFID); return; } NotificationCompat.Builder builder = new NotificationCompat.Builder(ctxt); Intent intent = new Intent(ctxt, WifiFixerActivity.class) .setAction(Intent.ACTION_MAIN) .setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); builder.setContentIntent(PendingIntent.getActivity(ctxt, 0, intent, 0)); builder.setOngoing(true); builder.setOnlyAlertOnce(true); builder.setOngoing(true); builder.setSmallIcon(R.drawable.logging_enabled); builder.setContentTitle(ctxt.getString(R.string.logservice)); builder.setContentText(getLogString(ctxt).toString()); /* * Fire the notification */ notify(ctxt, NotifUtil.LOGNOTIFID, LOG_TAG, builder.build()); }
private NotificationCompat.Builder createDefaultNotification() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); Intent onClick = new Intent(); onClick.setClassName( getPackageName(), /*Aptoide.getConfiguration().*/ getStartActivityClass().getName()); // TODO dependency injection onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.setAction(Intent.ACTION_VIEW); onClick.putExtra("fromDownloadNotification", true); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity( getApplicationContext(), 0, onClick, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setOngoing(true); mBuilder .setContentTitle( getString(R.string.aptoide_downloading, Aptoide.getConfiguration().getMarketName())) .setSmallIcon(R.drawable.stat_sys_download) .setProgress(0, 0, true) .setContentIntent(onClickAction); mBuilder.setProgress(100, 0, true); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)) .notify(-3, mBuilder.build()); return mBuilder; }
private Notification getNotification() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.launcher_icon) .setContentTitle("SleepMinder is active") .setContentText("Sleep well :)"); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, MainActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setProgress(0, 0, true); mBuilder.setCategory(NotificationCompat.CATEGORY_PROGRESS); mBuilder.setOngoing(true); PendingIntent stopTrackingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.addAction(R.drawable.ic_action_stop, "Stop tracking", stopTrackingIntent); return mBuilder.build(); }
private void initBuilder(String title, String content) { builder = new NotificationCompat.Builder(baseActivity.getBaseContext()); builder.setContentTitle(title); builder.setContentText(content); builder.setSmallIcon(R.drawable.ic_lets_go); builder.setPriority(NotificationCompat.PRIORITY_MAX); builder.setOngoing(true); }
public void startNotification() { builder.setSmallIcon(R.drawable.ic_stat_name); builder.setContentIntent(pendingIntent); builder.setAutoCancel(false); builder.setOngoing(true); builder.setContentTitle("Job Timer"); builder.setContentText("00:00:00"); notificationManager.notify(NOTIFICATION_ID, builder.build()); }
private void publishResults( String a, int p1, int p2, int id, long total, long done, boolean b, boolean move) { if (hash.get(id)) { mBuilder.setProgress(100, p1, false); mBuilder.setOngoing(true); int title = R.string.copying; if (move) title = R.string.moving; mBuilder.setContentTitle(utils.getString(c, title)); mBuilder.setContentText( new File(a).getName() + " " + utils.readableFileSize(done) + "/" + utils.readableFileSize(total)); int id1 = Integer.parseInt("456" + id); mNotifyManager.notify(id1, mBuilder.build()); if (p1 == 100 || total == 0) { mBuilder.setContentTitle("Copy completed"); if (move) mBuilder.setContentTitle("Move Completed"); mBuilder.setContentText(""); mBuilder.setProgress(0, 0, false); mBuilder.setOngoing(false); mBuilder.setAutoCancel(true); mNotifyManager.notify(id1, mBuilder.build()); publishCompletedResult(id, id1); } DataPackage intent = new DataPackage(); intent.setName(a); intent.setTotal(total); intent.setDone(done); intent.setId(id); intent.setP1(p1); intent.setP2(p2); intent.setMove(move); intent.setCompleted(b); hash1.put(id, intent); if (progressListener != null) { progressListener.onUpdate(intent); if (b) progressListener.refresh(); } } else publishCompletedResult(id, Integer.parseInt("456" + id)); }
public UploadImage(AppCompatActivity activity, String imageUri) { mActivity = activity; mImageUri = imageUri; mNotifyManager = (NotificationManager) mActivity.getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(mActivity); mBuilder .setContentTitle("Posting The Issue...") .setContentText("0%") .setSmallIcon(R.drawable.bullhorn_white); mBuilder.setAutoCancel(false); mBuilder.setOngoing(true); mBuilder.setProgress(100, 0, false); mNotifyManager.notify(id, mBuilder.build()); }
private static Notification updateSendDirectMessageNotification( final Context context, final NotificationCompat.Builder builder, final int progress, final String message) { builder.setContentTitle(context.getString(R.string.sending_direct_message)); if (message != null) { builder.setContentText(message); } builder.setSmallIcon(R.drawable.ic_stat_send); builder.setProgress(100, progress, progress >= 100 || progress <= 0); builder.setOngoing(true); return builder.build(); }
private static Notification updateUpdateStatusNotification( final Context context, final NotificationCompat.Builder builder, final int progress, final ParcelableStatusUpdate status) { builder.setContentTitle(context.getString(R.string.updating_status_notification)); if (status != null) { builder.setContentText(status.text); } builder.setSmallIcon(R.drawable.ic_stat_send); builder.setProgress(100, progress, progress >= 100 || progress <= 0); builder.setOngoing(true); return builder.build(); }
private NotificationCompat.Builder setNotification(final long id) { DownloadInfoRunnable info = getDownload(id); final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); // TODO Intent onClick = new Intent(); onClick.setClassName( getPackageName(), /*Aptoide.getConfiguration().*/ getStartActivityClass().getName()); onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.setAction(Intent.ACTION_VIEW); onClick.putExtra("fromDownloadNotification", true); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity( getApplicationContext(), 0, onClick, PendingIntent.FLAG_UPDATE_CURRENT); int size = DownloadUtils.dpToPixels(getApplicationContext(), 36); Bitmap icon = null; try { // icon = // DownloadUtils.decodeSampledBitmapFromResource(ImageLoader.getInstance().getDiscCache().get(info.getDownload().getIcon()).getAbsolutePath(), size, size); icon = GlideUtils.downloadOnlyFromCache( Aptoide.getContext(), info.getDownload().getIcon(), size, size); } catch (Exception e) { e.printStackTrace(); } mBuilder.setOngoing(true); mBuilder.setContentTitle( getString(R.string.aptoide_downloading, Aptoide.getConfiguration().getMarketName())); mBuilder.setContentText(info.getDownload().getName()); if (icon != null) mBuilder.setLargeIcon(icon); mBuilder.setSmallIcon(android.R.drawable.stat_sys_download); mBuilder.setProgress(0, 0, true); mBuilder.setContentIntent(onClickAction); // Log.d("download-trace", "ETA: " + info.getEta()); if (info.getEta() > 0) { String remaining = DownloadUtils.formatEta(info.getEta(), ""); mBuilder.setContentInfo("ETA: " + (!remaining.equals("") ? remaining : "0s")); } return mBuilder; }
private void notify(String text, boolean ongoing) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(ActivityMain.this); notificationBuilder.setSmallIcon(R.drawable.ic_launcher); notificationBuilder.setContentTitle(getString(R.string.menu_import)); notificationBuilder.setContentText(text); notificationBuilder.setWhen(System.currentTimeMillis()); if (ongoing) notificationBuilder.setOngoing(true); else notificationBuilder.setAutoCancel(true); Notification notification = notificationBuilder.build(); NotificationManager notificationManager = (NotificationManager) ActivityMain.this.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFY_ID, notification); }
private void showNotification() { mNotifMGR = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE); // notification for the task bar NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_music); builder.setContentTitle(mArtist[mSong]); builder.setContentText(mTitle[mSong]); builder.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), mArtwork[mSong])); builder.setAutoCancel(false); builder.setOngoing(true); NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle(); style.setBigContentTitle(mArtist[mSong]); style.setSummaryText(mTitle[mSong]); style.bigLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_music)); style.bigPicture(BitmapFactory.decodeResource(this.getResources(), mArtwork[mSong])); builder.setStyle(style); Intent skipIntent = new Intent(PREV_TRACK); PendingIntent pIntent = PendingIntent.getBroadcast(this, 0, skipIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(android.R.drawable.ic_media_rew, "Last Track", pIntent); skipIntent = new Intent(NEXT_TRACK); pIntent = PendingIntent.getBroadcast(this, 0, skipIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(android.R.drawable.ic_media_ff, "Next Track", pIntent); Intent clickIntent = new Intent(this, MainActivity.class); clickIntent.putExtra(MainFragment.EXTRA_TITLE_UPDATE, mTitle[mSong]); clickIntent.putExtra(MainFragment.EXTRA_COVER_UPDATE, mArtwork[mSong]); clickIntent.putExtra(MainFragment.EXTRA_ARTIST_UPDATE, mArtist[mSong]); clickIntent.putExtra(MainFragment.EXTRA_SONG_DURATION, mPlayer.getDuration()); PendingIntent pendClickIntent = PendingIntent.getActivity(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendClickIntent); Notification notification = builder.build(); startForeground(NOTIF_ID, notification); }
/** Notify user about running server and connected clients */ public synchronized void notifyUser(String title, String message, boolean ongoing) { PendingIntent intent = PendingIntent.getActivity(AppContext, 0, new Intent(AppContext, main.class), 0); String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) AppContext.getSystemService(ns); NotificationCompat.Builder notificationbuilder = new NotificationCompat.Builder(AppContext); notificationbuilder.setContentTitle(title); notificationbuilder.setContentText(message); notificationbuilder.setTicker(message); notificationbuilder.setSmallIcon(R.drawable.ic_launcher); notificationbuilder.setContentIntent(intent); notificationbuilder.setOngoing(ongoing); Notification notification = notificationbuilder.getNotification(); mNotificationManager.notify(1, notification); }
@Override public void handleMessage(Message msg) { super.handleMessage(msg); NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(MainActivity.this) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle(getString(R.string.app_name)); AlertDialog.Builder aBuilder = new AlertDialog.Builder(MainActivity.this); Bundle bundle = msg.getData(); switch (bundle.getInt(Constants.SERVER_THREAD_STATUS)) { case Constants.SERVER_THREAD_STATUS_LISTENING: nBuilder.setContentText( getString(R.string.listening) + " " + bundle.getString(Constants.IP_ADDRESS)); nBuilder.setOngoing(true); break; case Constants.SERVER_THREAD_STATUS_WIFI_NOT_CONNECTED: aBuilder.setIcon(R.mipmap.ic_launcher); aBuilder.setTitle(getString(R.string.app_name)); aBuilder.setMessage(getString(R.string.wifi_not_connected)); aBuilder.setPositiveButton( getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancelAll(); System.exit(0); } }); aBuilder.setCancelable(false); aBuilder.show(); return; case Constants.SERVER_THREAD_STATUS_INIT_FAILED: nBuilder.setContentText(getString(R.string.init_failed)); break; default: nBuilder.setContentText(getString(R.string.unknown_error)); break; } NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(Constants.SERVER_NOTIFICATION_ID, nBuilder.build()); }
private Notification generateNotification() { // 通知領域タップ時のPendingIntentを生成 Intent actionIntent = new Intent(getApplicationContext(), Ch0708.class); PendingIntent pi = PendingIntent.getActivity( getApplicationContext(), 0, actionIntent, PendingIntent.FLAG_UPDATE_CURRENT); // 独自レイアウトのRemoveViewを生成 RemoteViews mNotificationView = new RemoteViews(getPackageName(), R.layout.ch0708_statusbar); // Notificationの生成 NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()); builder.setSmallIcon(R.drawable.ic_stat_media); // 独自レイアウトをNotificaitonに設定 builder.setContent(mNotificationView); // trueで常に通知領域に表示 builder.setOngoing(true); // 通知領域に初期表示時のメッセージを設定 builder.setTicker("Sample Titleを再生"); builder.setContentIntent(pi); // ステータスバーのレイアウトに設定されているイメージアイコンにアイコンを設定 mNotificationView.setImageViewResource(R.id.imageicon, R.drawable.ic_launcher); // ステータスバーのレイアウトに設定されているタイトル名にタイトルを設定 mNotificationView.setTextViewText(R.id.textTitle, "Sample Title"); // ステータスバーのレイアウトに設定されているアーティスト名にアーティストを設定 mNotificationView.setTextViewText(R.id.textArtist, "Sample Artist"); // [イメージアイコン]ボタンを押された際に呼ばれるIntentを設定 PendingIntent contentIntent = PendingIntent.getActivity( this, 0, new Intent(this, Ch0708.class), Intent.FLAG_ACTIVITY_NEW_TASK); mNotificationView.setOnClickPendingIntent(R.id.imageicon, contentIntent); // [再生]・[一時停止]ボタンを押された際に呼ばれるIntentを設定 mNotificationView.setOnClickPendingIntent(R.id.btnPlay, createPendingIntent("playpause")); // [次へ]ボタンを押された際に呼ばれるIntentを設定 mNotificationView.setOnClickPendingIntent(R.id.btnNext, createPendingIntent("next")); return builder.build(); }
private void showPostUpdateNotification() { // Remove the old one mNotificationManager.cancel(NOTIFICATION_ID); mBuilder = new NotificationCompat.Builder(getApplicationContext()); mBuilder.setTicker(getString(R.string.finishedTraktMovieSync)); mBuilder.setContentTitle(getString(R.string.finishedTraktMovieSync)); mBuilder.setSmallIcon(R.drawable.done); mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.done)); mBuilder.setOngoing(false); mBuilder.setAutoCancel(true); mBuilder.setOnlyAlertOnce(true); // Build notification Notification updateNotification = mBuilder.build(); // Show the notification mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(NOTIFICATION_ID + 1000, updateNotification); }
@Override protected void onHandleIntent(Intent intent) { mNotifyManager = (NotificationManager) getApplication().getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(this); id++; mBuilder.setContentTitle(getResources().getString(R.string.working)); // mBuilder.setContentText(getResources().getString(R.string.workingU)); mBuilder.setSmallIcon(R.drawable.ic_action_not_secure); mBuilder.setProgress(0, 0, true); mBuilder.setOngoing(true); startForeground(id, mBuilder.build()); if (intent != null) { int idC = intent.getExtras().getInt(Constants.CRYPTO_CONTROLLER); manejarMedia(idC); // manejarMediaParalelo(idC); } mNotifyManager.cancel(id); }
private void setupNotification() { // Setup up notification mBuilder = new NotificationCompat.Builder(getApplicationContext()); mBuilder.setSmallIcon(R.drawable.ic_action_tv); mBuilder.setTicker(getString(R.string.syncMovies)); mBuilder.setContentTitle(getString(R.string.syncMovies)); mBuilder.setContentText(getString(R.string.updatingMovieInfo)); mBuilder.setOngoing(true); mBuilder.setOnlyAlertOnce(true); mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_tv)); // Build notification Notification updateNotification = mBuilder.build(); // Show the notification mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(NOTIFICATION_ID, updateNotification); // Tell the system that this is an ongoing notification, so it shouldn't be killed startForeground(NOTIFICATION_ID, updateNotification); }
@Override public int onStartCommand(Intent intent, int flags, int startId) { Intent i = new Intent(this, MainActivity.class); PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0); String title = getString(R.string.notification_title); String content = getString(R.string.notification_state_locked); NotificationCompat.Builder nb = new NotificationCompat.Builder(this); nb.setSmallIcon(R.drawable.ic_launcher); nb.setContentTitle(title); nb.setContentText(content); nb.setWhen(System.currentTimeMillis()); nb.setContentIntent(pi); nb.setOngoing(true); startForeground(AppLockService.NOTIFICATION_ID, nb.build()); stopForeground(true); startForeground(MonitorService.NOTIFICATION_ID, nb.build()); stopForeground(true); stopSelf(); return START_NOT_STICKY; }
public Notification createNotification() { mNotifyBuild = new NotificationCompat.Builder(mController.getApplicationContext()) .setContentTitle(mController.getString(R.string.balatafm)) .setSmallIcon(R.drawable.ic_notification) .setContentIntent(getPendingIntent()); mNotifyBuild.setContentText(getNotificationString()); if (mPlayerState.isBuffering()) { mNotifyBuild.setProgress(0, 0, true); } else { if (mPlayerState.isPlaying()) { mNotifyBuild.addAction(R.drawable.player_stop, "Stop", getBroadcastIntent("stop")); mNotifyBuild.setOngoing(true); } else { mNotifyBuild.addAction(R.drawable.player_play, "Play", getBroadcastIntent("play")); } } mNotificationVisible = true; return mNotifyBuild.build(); }
/** * Build notification info * * @param context The calling activity * @param drawable The notification icon * @param message The message * @param title The title for the notification * @param intent The pending intent * @param ongoing True if you don't want the user to clear the notification */ public static void buildNotification( Context context, int drawable, String message, String title, PendingIntent intent, boolean ongoing) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContentTitle(title); builder.setContentText(message); builder.setSmallIcon(drawable); builder.setContentIntent(intent); if (ongoing) { builder.setOngoing(ongoing); } notificationManager.notify(NOTIFY_RUNNING, builder.getNotification()); }
@Override public void vaddStatNotif(final Context ctxt, final StatusMessage in) { StatusMessage m = validateStrings(in); if (m.getShow() != 1) { vcancel(ctxt, STAT_TAG, NotifUtil.STATNOTIFID); return; } if (NotifUtil.ssidStatus == NotifUtil.SSID_STATUS_UNMANAGED) { m.setStatus( new StringBuilder(ctxt.getString(R.string.unmanaged)).append(m.getStatus()).toString()); } NotificationCompat.Builder statbuilder = new NotificationCompat.Builder(ctxt); Intent intent = new Intent(ctxt, WifiFixerActivity.class) .setAction(Intent.ACTION_MAIN) .setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); statbuilder.setContentIntent(PendingIntent.getActivity(ctxt, 0, intent, 0)); statbuilder.setOnlyAlertOnce(true); statbuilder.setOngoing(true); statbuilder.setWhen(0); statbuilder.setPriority(NotificationCompat.PRIORITY_MIN); statbuilder.setSmallIcon(getIconfromSignal(m.getSignal(), ICON_SET_SMALL)); statbuilder.setLargeIcon( BitmapFactory.decodeResource( ctxt.getResources(), getIconfromSignal(m.getSignal(), ICON_SET_LARGE))); statbuilder.setContentText(m.getStatus()); statbuilder.setSubText(ctxt.getString(R.string.network_status)); statbuilder.setContentTitle(m.getSSID()); /* * Fire the notification */ notify(ctxt, NotifUtil.STATNOTIFID, STAT_TAG, statbuilder.build()); }
void showNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_stat_notify); builder.setTicker(getResources().getString(R.string.plumbleConnected)); builder.setContentTitle(getResources().getString(R.string.app_name)); builder.setContentText(getResources().getString(R.string.connected)); builder.setPriority(NotificationCompat.PRIORITY_HIGH); builder.setOngoing(true); // Add notification triggers Intent muteIntent = new Intent(this, MumbleService.class); muteIntent.putExtra(MUMBLE_NOTIFICATION_ACTION_KEY, MUMBLE_NOTIFICATION_ACTION_MUTE); Intent deafenIntent = new Intent(this, MumbleService.class); deafenIntent.putExtra(MUMBLE_NOTIFICATION_ACTION_KEY, MUMBLE_NOTIFICATION_ACTION_DEAFEN); builder.addAction( R.drawable.ic_action_microphone, getString(R.string.mute), PendingIntent.getService(this, 0, muteIntent, PendingIntent.FLAG_CANCEL_CURRENT)); builder.addAction( R.drawable.ic_action_headphones, getString(R.string.deafen), PendingIntent.getService(this, 1, deafenIntent, PendingIntent.FLAG_CANCEL_CURRENT)); Intent channelListIntent = new Intent(MumbleService.this, ChannelActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, channelListIntent, 0); builder.setContentIntent(pendingIntent); mStatusNotificationBuilder = builder; mStatusNotification = mStatusNotificationBuilder.build(); startForeground(STATUS_NOTIFICATION_ID, mStatusNotification); }
private boolean updateNotification(final Context context) { Log.d(TAG, "updateNotification()"); lastUpdate = System.currentTimeMillis(); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); ArrayList<Timer> timers = new ArrayList<Timer>(); mNow = System.currentTimeMillis(); mNextTarget = 0; boolean alert = false; Log.d(TAG, "mNow: " + mNow); for (int j = 0; j < Timer.TIMER_IDS.length; j++) { Timer t = new Timer(context, j); timers.add(t); long tt = t.getTarget(); Log.d(TAG, "target(" + j + "): " + tt); if (tt > 0) { if (mNextTarget == 0 || tt < mNextTarget) { mNextTarget = tt; } if (tt < mNow) { alert = true; t.reset(context); } } } Log.d(TAG, "mNextTarget: " + mNextTarget); NotificationCompat.Builder b = new NotificationCompat.Builder(context); b.setPriority(1000); Intent i = new Intent(context, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); b.setContentIntent(PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT)); b.setContentTitle(context.getString(R.string.app_name)); b.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher)); b.setSmallIcon(R.drawable.ic_stat_timer); b.setAutoCancel(false); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { // GB- b.setContentText( context.getString( R.string.notification_text, timers.get(0).getFormatted(), timers.get(1).getFormatted(), timers.get(2).getFormatted())); } else { // HC+ RemoteViews v = new RemoteViews(context.getPackageName(), R.layout.notification); for (int j = 0; j < Timer.TIMER_IDS.length; j++) { v.setTextViewText(Timer.TIMER_IDS[j], timers.get(j).getFormatted().toString()); Intent ij = new Intent(Timer.TIMER_KEYS[j], null, context, UpdateReceiver.class); v.setOnClickPendingIntent( Timer.TIMER_IDS[j], PendingIntent.getBroadcast(context, 0, ij, PendingIntent.FLAG_UPDATE_CURRENT)); } v.setOnClickPendingIntent( R.id.settings, PendingIntent.getActivity( context, 0, new Intent(context, SettingsActivity.class), PendingIntent.FLAG_UPDATE_CURRENT)); b.setContent(v); } if (mNextTarget <= 0 && !alert) { // we don't need any notification b.setOngoing(false); nm.notify(0, b.build()); return false; } else if (alert) { // show notification without running Timer b.setOngoing(mNextTarget > 0); SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); if (p.getBoolean("vibrate", true)) { b.setVibrate(VIBRATE); } String n = p.getString("notification", null); if (n == null) { // default b.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } else if (n.length() > 1) { try { b.setSound(Uri.parse(n)); } catch (Exception e) { Log.e(TAG, "invalid notification uri", e); b.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } // else: silent nm.notify(0, b.build()); return true; } else { // show notification with running Timer b.setOngoing(true); nm.notify(0, b.build()); return true; } }
private void showNotification(JSONObject message) { NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); // These attributes are required final String id; try { builder.setContentTitle(message.getString(TITLE_ATTR)); builder.setContentText(message.getString(TEXT_ATTR)); id = message.getString(ID_ATTR); } catch (JSONException ex) { Log.i(LOGTAG, "Error parsing", ex); return; } Uri imageUri = Uri.parse(message.optString(SMALLICON_ATTR)); builder.setSmallIcon(BitmapUtils.getResource(imageUri, R.drawable.ic_status_logo)); JSONArray light = message.optJSONArray(LIGHT_ATTR); if (light != null && light.length() == 3) { try { builder.setLights(light.getInt(0), light.getInt(1), light.getInt(2)); } catch (JSONException ex) { Log.i(LOGTAG, "Error parsing", ex); } } boolean ongoing = message.optBoolean(ONGOING_ATTR); builder.setOngoing(ongoing); if (message.has(WHEN_ATTR)) { long when = message.optLong(WHEN_ATTR); builder.setWhen(when); } if (message.has(PRIORITY_ATTR)) { int priority = message.optInt(PRIORITY_ATTR); builder.setPriority(priority); } if (message.has(LARGE_ICON_ATTR)) { Bitmap b = BitmapUtils.getBitmapFromDataURI(message.optString(LARGE_ICON_ATTR)); builder.setLargeIcon(b); } if (message.has(PROGRESS_VALUE_ATTR) && message.has(PROGRESS_MAX_ATTR) && message.has(PROGRESS_INDETERMINATE_ATTR)) { try { final int progress = message.getInt(PROGRESS_VALUE_ATTR); final int progressMax = message.getInt(PROGRESS_MAX_ATTR); final boolean progressIndeterminate = message.getBoolean(PROGRESS_INDETERMINATE_ATTR); builder.setProgress(progressMax, progress, progressIndeterminate); } catch (JSONException ex) { Log.i(LOGTAG, "Error parsing", ex); } } JSONArray actions = message.optJSONArray(ACTIONS_ATTR); if (actions != null) { try { for (int i = 0; i < actions.length(); i++) { JSONObject action = actions.getJSONObject(i); final PendingIntent pending = buildButtonClickPendingIntent(message, action); final String actionTitle = action.getString(ACTION_TITLE_ATTR); final Uri actionImage = Uri.parse(action.optString(ACTION_ICON_ATTR)); builder.addAction( BitmapUtils.getResource(actionImage, R.drawable.ic_status_logo), actionTitle, pending); } } catch (JSONException ex) { Log.i(LOGTAG, "Error parsing", ex); } } PendingIntent pi = buildNotificationPendingIntent(message, CLICK_EVENT); builder.setContentIntent(pi); PendingIntent deletePendingIntent = buildNotificationPendingIntent(message, CLEARED_EVENT); builder.setDeleteIntent(deletePendingIntent); GeckoAppShell.notificationClient.add(id.hashCode(), builder.build()); boolean persistent = message.optBoolean(PERSISTENT_ATTR); // We add only not persistent notifications to the list since we want to purge only // them when geckoapp is destroyed. if (!persistent && !mClearableNotifications.containsKey(id)) { mClearableNotifications.put(id, message.toString()); } }
@Override public Builder setOngoing(boolean ongoing) { super.setOngoing(ongoing); return this; }