@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()); }
/** * Generate a notification * * @param pendingIntent pending intent * @param title title * @param message message * @return the notification */ private Notification buildNotification( PendingIntent pendingIntent, String title, String message) { NotificationCompat.Builder notif = new NotificationCompat.Builder(this); notif.setContentIntent(pendingIntent); notif.setSmallIcon(R.drawable.ri_notif_file_transfer_icon); notif.setWhen(System.currentTimeMillis()); notif.setAutoCancel(true); notif.setOnlyAlertOnce(true); notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); notif.setDefaults(Notification.DEFAULT_VIBRATE); notif.setContentTitle(title); notif.setContentText(message); return notif.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); }
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); }
private void addSessionInvitationNotification(Intent intent, ContactId contact) { /* Create pending intent */ Intent invitation = new Intent(intent); String title; if (mMultimediaMessagingSession) { invitation.setClass(this, MessagingSessionView.class); title = getString(R.string.title_recv_messaging_session); } else { invitation.setClass(this, StreamingSessionView.class); title = getString(R.string.title_recv_streaming_session); } invitation.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); /* * If the PendingIntent has the same operation, action, data, categories, components, and * flags it will be replaced. Invitation should be notified individually so we use a random * generator to provide a unique request code and reuse it for the notification. */ int uniqueId = Utils.getUniqueIdForPendingIntent(); PendingIntent contentIntent = PendingIntent.getActivity(this, uniqueId, invitation, PendingIntent.FLAG_ONE_SHOT); String displayName = RcsContactUtil.getInstance(this).getDisplayName(contact); /* Create notification */ NotificationCompat.Builder notif = new NotificationCompat.Builder(this); notif.setContentIntent(contentIntent); notif.setSmallIcon(R.drawable.ri_notif_mm_session_icon); notif.setWhen(System.currentTimeMillis()); notif.setAutoCancel(true); notif.setOnlyAlertOnce(true); notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); notif.setDefaults(Notification.DEFAULT_VIBRATE); notif.setContentTitle(title); notif.setContentText(getString(R.string.label_from_args, displayName)); /* Send notification */ NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(uniqueId, notif.build()); }
@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()); }
@Override public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { super.setOnlyAlertOnce(onlyAlertOnce); return this; }
public void notify( String notificationId, String apiKey, String title, String message, String uri, String imageUrl) { Log.d(LOGTAG, "notify()..."); Log.d(LOGTAG, "notificationId=" + notificationId); Log.d(LOGTAG, "notificationApiKey=" + apiKey); Log.d(LOGTAG, "notificationTitle=" + title); Log.d(LOGTAG, "notificationMessage=" + message); Log.d(LOGTAG, "notificationUri=" + uri); if (isNotificationEnabled()) { // Show the toast if (isNotificationToastEnabled()) { Toast.makeText(context, message, Toast.LENGTH_LONG).show(); } mBuilder .setWhen(System.currentTimeMillis()) // 通知产生的时间,会在通知信息里显示 .setPriority(Notification.PRIORITY_DEFAULT) // 设置该通知优先级 // .setAutoCancel(true)//设置这个标志当用户单击面板就可以让通知将自动取消 .setOngoing( false) // ture,设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此占用设备(如一个文件下载,同步操作,主动网络连接) .setDefaults( Notification .DEFAULT_VIBRATE) // 向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合: // Notification.DEFAULT_ALL Notification.DEFAULT_SOUND 添加声音 // requires VIBRATE // permission .setSmallIcon(getNotificationIcon()); mBuilder .setAutoCancel(true) // 点击后让通知将消失 .setContentTitle(title) .setContentText(message) .setTicker(message); // Notification if (isNotificationSoundEnabled()) { mBuilder.setDefaults(Notification.DEFAULT_SOUND); } if (isNotificationVibrateEnabled()) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } mBuilder.setOnlyAlertOnce(true); // Intent intent; // if (uri != null // && uri.length() > 0 // && (uri.startsWith("http:") || uri.startsWith("https:") // || uri.startsWith("tel:") || uri.startsWith("geo:"))) { // intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); // } else { // String callbackActivityPackageName = sharedPrefs.getString( // Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, ""); // String callbackActivityClassName = sharedPrefs.getString( // Constants.CALLBACK_ACTIVITY_CLASS_NAME, ""); // intent = new Intent().setClassName(callbackActivityPackageName, // callbackActivityClassName); // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // } Intent intent = new Intent(context, NotificationDetailsActivity.class); intent.putExtra(Constants.NOTIFICATION_ID, notificationId); intent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey); intent.putExtra(Constants.NOTIFICATION_TITLE, title); intent.putExtra(Constants.NOTIFICATION_MESSAGE, message); intent.putExtra(Constants.NOTIFICATION_URI, uri); intent.putExtra(Constants.NOTIFICATION_IMAGE_URL, imageUrl); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity( context, random.nextInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(contentIntent); notificationManager.notify(random.nextInt(), mBuilder.build()); } else { Log.w(LOGTAG, "Notificaitons disabled."); } }