List of usage examples for android.support.v4.app TaskStackBuilder getPendingIntent
public PendingIntent getPendingIntent(int requestCode, int flags)
From source file:com.group13.androidsdk.mycards.NotificationService.java
private void sendNotification() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.small_logo).setContentTitle("Time to review!") .setContentText("You should review some flashcards!").setAutoCancel(true) .setVibrate(new long[] { 0, 100, 300, 80, 80, 80 }); Intent resultIntent = new Intent(this, ReviewActivity.class); resultIntent.putExtra("notificationId", 12); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.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(12, mBuilder.build()); }
From source file:org.creativecommons.thelist.utils.MessageHelper.java
public void sendNotification(Context context, String title, String message, String ticker) { //Bitmap largeIcon = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_launcher); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_camera_alt_white_24dp).setContentTitle(title).setContentText(message) .setTicker(ticker);/*w ww. j a v a 2 s. c om*/ Intent resultIntent = new Intent(mContext, MainActivity.class); android.support.v4.app.TaskStackBuilder stackBuilder = android.support.v4.app.TaskStackBuilder .create(mContext); stackBuilder.addParentStack(StartActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager manager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(getNotificationID(), mBuilder.build()); }
From source file:com.moto.miletus.application.ble.neardevice.NearDeviceNotification.java
/** * notification/* w ww. java 2 s. c o m*/ * * @param room String * @param light ParameterValue * @param temp ParameterValue */ private void notification(final String room, final ParameterValue light, final ParameterValue temp) { String msg; if (room == null) { systemService.cancelAll(); return; } else if (light != null && temp != null) { msg = "Welcome to: " + room + Strings.NEW_LINE + "Light: " + light.getValue() + Strings.LUX + Strings.NEW_LINE; try { String tempRound = Precision.round(Float.parseFloat(temp.getValue()), 1) + ""; msg = msg + "Temp: " + tempRound + Strings.CELSIUS + Strings.NEW_LINE; } catch (NumberFormatException ex) { Log.e(TAG, ex.toString()); } } else { msg = "Welcome to: " + room + Strings.NEW_LINE; } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.miletus).setContentTitle("Room Status") .setPriority(NotificationCompat.PRIORITY_MAX).setContentText(msg); Intent resultIntent = new Intent(context, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); systemService.notify(9812, mBuilder.build()); Log.i(TAG, msg); }
From source file:com.google.android.apps.santatracker.cast.DataCastNotificationService.java
private void build(int titleId, int imageId) { // Main Content PendingIntent Intent contentIntent = new Intent(this, INTENT_ACTIVITY); // Disconnect PendingIntent Intent stopIntent = new Intent(ACTION_STOP); stopIntent.setPackage(getPackageName()); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0); // Media metadata String castingTo = getResources().getString(R.string.ccl_casting_to_device, mCastManager.getDeviceName()); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(INTENT_ACTIVITY); stackBuilder.addNextIntent(contentIntent); PendingIntent contentPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_small).setContentTitle(getResources().getString(titleId)) .setContentText(castingTo).setContentIntent(contentPendingIntent) .setColor(ContextCompat.getColor(this, R.color.brandSantaTracker)) .addAction(R.drawable.ic_notification_disconnect_24dp, getString(R.string.ccl_disconnect), stopPendingIntent)/*from ww w . j ava 2 s.c om*/ .setOngoing(true).setShowWhen(false).setVisibility(NotificationCompat.VISIBILITY_PUBLIC); mNotification = builder.build(); }
From source file:com.apexlabs.alarm.AlarmService.java
private void postNotification() { Log.d(TAG, "posting notification"); mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.transparent) //.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.alarm_white)) .setContentTitle(getResources().getString(R.string.notification_title)) .setContentText("Next Alarm is " + Settings.System .getString(getContentResolver(), Settings.System.NEXT_ALARM_FORMATTED).toString()); notificationPosted = true;//from w ww.j av a 2 s .c o m Intent nIntent = getClockIntent(); nIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(AlarmNotification.class); stackBuilder.addNextIntent(nIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); // should make mId random mId = 867; mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(mId, mBuilder.build()); }
From source file:com.nogago.android.tracks.widgets.TrackWidgetProvider.java
/** * Updates view.//w w w. j av a2 s.c o m * * @param remoteViews the remote views */ private void updateView(RemoteViews remoteViews) { Track track = selectedTrackId != PreferencesUtils.SELECTED_TRACK_ID_DEFAULT ? myTracksProviderUtils.getTrack(selectedTrackId) : myTracksProviderUtils.getLastTrack(); TripStatistics tripStatistics = track == null ? null : track.getTripStatistics(); String distance = tripStatistics == null ? unknown : StringUtils.formatDistance(context, tripStatistics.getTotalDistance(), metricUnits); int timeLabelId = useTotalTime ? R.string.stats_total_time : R.string.stats_moving_time; String time = tripStatistics == null ? unknown : StringUtils.formatElapsedTime( useTotalTime ? tripStatistics.getTotalTime() : tripStatistics.getMovingTime()); int speedLabelId; if (useTotalTime) { speedLabelId = reportSpeed ? R.string.stats_average_speed : R.string.stats_average_pace; } else { speedLabelId = reportSpeed ? R.string.stats_average_moving_speed : R.string.stats_average_moving_pace; } String speed = tripStatistics == null ? unknown : StringUtils.formatSpeed(context, useTotalTime ? tripStatistics.getAverageSpeed() : tripStatistics.getAverageMovingSpeed(), metricUnits, reportSpeed); remoteViews.setTextViewText(R.id.track_widget_distance_value, distance); remoteViews.setTextViewText(R.id.track_widget_time_label, context.getString(timeLabelId)); remoteViews.setTextViewText(R.id.track_widget_time_value, time); remoteViews.setTextViewText(R.id.track_widget_speed_label, context.getString(speedLabelId)); remoteViews.setTextViewText(R.id.track_widget_speed_value, speed); Intent intent; if (track != null) { intent = IntentUtils.newIntent(context, TrackDetailActivity.class) .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, track.getId()); } else { intent = IntentUtils.newIntent(context, TrackListActivity.class); } TaskStackBuilder taskStackBuilder = TaskStackBuilder.from(context); taskStackBuilder.addNextIntent(intent); PendingIntent pendingIntent = taskStackBuilder.getPendingIntent(0, 0); remoteViews.setOnClickPendingIntent(R.id.track_widget_statistics, pendingIntent); remoteViews.setOnClickPendingIntent(R.id.track_widget_icon, pendingIntent); }
From source file:org.kde.kdeconnect.Plugins.ReceiveNotificationsPlugin.ReceiveNotificationsPlugin.java
@Override public boolean onPackageReceived(final NetworkPackage np) { if (!np.has("ticker") || !np.has("appName") || !np.has("id")) { Log.e("NotificationsPlugin", "Received notification package lacks properties"); } else {//w ww .j a v a 2s .co m TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MaterialActivity.class); stackBuilder.addNextIntent(new Intent(context, MaterialActivity.class)); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap largeIcon = null; if (np.hasPayload()) { int width = 64; // default icon dimensions int height = 64; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { width = context.getResources() .getDimensionPixelSize(android.R.dimen.notification_large_icon_width); height = context.getResources() .getDimensionPixelSize(android.R.dimen.notification_large_icon_height); } final InputStream input = np.getPayload(); largeIcon = BitmapFactory.decodeStream(np.getPayload()); try { input.close(); } catch (Exception e) { } if (largeIcon != null) { //Log.i("NotificationsPlugin", "hasPayload: size=" + largeIcon.getWidth() + "/" + largeIcon.getHeight() + " opti=" + width + "/" + height); if (largeIcon.getWidth() > width || largeIcon.getHeight() > height) { // older API levels don't scale notification icons automatically, therefore: largeIcon = Bitmap.createScaledBitmap(largeIcon, width, height, false); } } } Notification noti = new NotificationCompat.Builder(context).setContentTitle(np.getString("appName")) .setContentText(np.getString("ticker")).setContentIntent(resultPendingIntent) .setTicker(np.getString("ticker")).setSmallIcon(R.drawable.ic_notification) .setLargeIcon(largeIcon).setAutoCancel(true).setLocalOnly(true) // to avoid bouncing the notification back to other kdeconnect nodes .setDefaults(Notification.DEFAULT_ALL).build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); NotificationHelper.notifyCompat(notificationManager, "kdeconnectId:" + np.getString("id", "0"), np.getInt("id", 0), noti); } return true; }
From source file:nkarasch.repeatingreminder.scheduling.AlertBroadcastReceiver.java
private void fireNotification(Context context, Alert alert) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.notification_icon).setContentTitle(context.getString(R.string.app_name)) .setContentText(alert.getLabel()); if (alert.isVibrate()) { builder.setDefaults(NotificationCompat.DEFAULT_VIBRATE); }/*from ww w . j a v a2s . c om*/ if (alert.isLight()) { builder.setLights(0xffff00ff, 1000, 300); } if (!alert.isMute()) { builder.setSound(alert.getToneURI()); } builder.setPriority(NotificationCompat.PRIORITY_DEFAULT); Intent homeIntent = new Intent(context, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(homeIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(alert.getId(), builder.build()); }
From source file:com.google.android.apps.mytracks.widgets.TrackWidgetProvider.java
/** * Updates the statistics container./*from w w w .j a v a 2 s .c om*/ * * @param context the context * @param remoteViews the remote views * @param track the track */ private void updateStatisticsContainer(Context context, RemoteViews remoteViews, Track track) { Intent intent; if (track != null) { intent = IntentUtils.newIntent(context, TrackDetailActivity.class) .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, track.getId()); } else { intent = IntentUtils.newIntent(context, TrackListActivity.class); } TaskStackBuilder taskStackBuilder = TaskStackBuilder.from(context); taskStackBuilder.addNextIntent(intent); PendingIntent pendingIntent = taskStackBuilder.getPendingIntent(0, 0); remoteViews.setOnClickPendingIntent(R.id.track_widget_statistics, pendingIntent); remoteViews.setOnClickPendingIntent(R.id.track_widget_labels, pendingIntent); remoteViews.setOnClickPendingIntent(R.id.track_widget_logo_button, pendingIntent); }
From source file:com.z3r0byte.magistify.Services.AppointmentService.java
private void notificationTimer() { TimerTask notificationTask = new TimerTask() { @Override//ww w. j a v a2 s. c o m public void run() { Gson gson = new Gson(); Appointment[] appointments = calendarDB.getNotificationAppointments(); Log.d(TAG, "run: amount " + appointments.length); previousAppointment = configUtil.getString("previous_appointment"); if (appointments.length >= 1) { Appointment appointment = appointments[0]; if (!gson.toJson(appointment).equals(previousAppointment) && isCandidate(appointment)) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( getApplicationContext()); 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:"); } mBuilder.setContentText(appointment.description + " in " + appointment.location); mBuilder.setAutoCancel(true); mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); Intent resultIntent = new Intent(getApplicationContext(), AppointmentActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext()); stackBuilder.addParentStack(AppointmentActivity.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(9991, mBuilder.build()); previousAppointment = gson.toJson(appointment); configUtil.setString("previous_appointment", previousAppointment); } } else { NotificationManager notifManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notifManager.cancel(9991); } } }; timer.schedule(notificationTask, 20000, 30 * 1000); }