List of usage examples for android.app NotificationManager notify
public void notify(int id, Notification notification)
From source file:GCMService.java
private void sendNotification(String message) { Log.i("GCMService", "sendNotification()"); Uri notificationSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("GCM Message").setContentText(message) .setSound(notificationSoundUri).setLights(Color.BLUE, 500, 500); NotificationManager notificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }
From source file:co.madteam.activityrecognitionexample.services.ActivityRecognitionIntentService.java
@Override protected void onHandleIntent(Intent intent) { // Get the ActivityRecognitionResult ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent); // Get the list of the probable activities ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities(); String type = ""; float confidence = 0; // Select the most confidence type for (DetectedActivity da : detectedActivities) { if (da.getConfidence() > confidence) { confidence = da.getConfidence(); type = Constants.getActivityString(getApplicationContext(), da.getType()); }//w w w. j av a2 s . com } // Add to the notification the current most confidence activity NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Current activity: " + type).setOngoing(true) .setContentText("Confidence: " + String.valueOf(confidence) + "%"); int mNotificationId = Constants.NOTIFICATION_ID; NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mNotifyMgr.notify(mNotificationId, mBuilder.build()); }
From source file:com.careme.apvereda.careme.DailyAlarm.java
@Override public void onReceive(Context context, Intent intent) { Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_notifications); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.mipmap.ic_notsmall).setLargeIcon(bitmap) .setContentTitle(context.getResources().getText(R.string.notifTittle)) .setContentText(context.getResources().getText(R.string.notifBody)) .setVibrate(new long[] { 100, 250, 100, 500 }); Intent resultIntent = new Intent(context, MainActivity.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); int mNotificationId = 001; NotificationManager mNotifyMgr = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotifyMgr.notify(mNotificationId, mBuilder.build()); }
From source file:com.contactlab.clabpush_android_sample.GcmListenerService.java
private void sendNotification(String message) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_template_icon_bg).setContentTitle("GCM Message") .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:GeofenceIntentService.java
private void sendNotification() { Log.i("GeofenceIntentService", "sendNotification()"); Uri notificationSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Geofence Alert") .setContentText("GEOFENCE_TRANSITION_DWELL").setSound(notificationSoundUri) .setLights(Color.BLUE, 500, 500); NotificationManager notificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }
From source file:com.apptentive.android.example.push.MyGcmListenerService.java
@Override public void onMessageReceived(String from, Bundle data) { String title = data.getString("gcm.notification.title"); String body = data.getString("gcm.notification.body"); ApptentiveLog.e("From: " + from); ApptentiveLog.e("Title: " + title); ApptentiveLog.e("Body: " + body); Intent intent = new Intent(this, ExampleActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Apptentive.setPendingPushNotification(data); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification).setContentTitle(title).setContentText(body) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.jaguarlandrover.auto.remote.vehicleentry.RviService.java
static void sendNotification(Context ctx, String action, String... extras) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); boolean fire = prefs.getBoolean("pref_fire_notifications", true); if (!fire)/* ww w .j av a2 s .c om*/ return; NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx).setSmallIcon(R.drawable.rvi_not) .setAutoCancel(true).setContentTitle(ctx.getResources().getString(R.string.app_name)) .setContentText(action); Intent targetIntent = new Intent(ctx, LockActivity.class); int j = 0; for (String ex : extras) { targetIntent.putExtra("_extra" + (++j), ex); targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); } PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(contentIntent); nm.notify(0, builder.build()); }
From source file:de.ub0r.android.websms.connector.common.Utils.java
/** * Show update notification.//from w w w. j a va 2s . c o m * * @param context * {@link Context} * @param pkg * package */ public static void showUpdateNotification(final Context context, final String pkg) { Notification n = new Notification(android.R.drawable.stat_sys_warning, context.getString(R.string.update_title), 0); n.flags = Notification.FLAG_AUTO_CANCEL; PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + pkg)), PendingIntent.FLAG_UPDATE_CURRENT); n.setLatestEventInfo(context, context.getString(R.string.update_title), context.getString(R.string.update_message), pi); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(0, n); }
From source file:net.frygo.findmybuddy.GCMIntentService.java
private static void generateAcceptfriendNotification(Context context, String message, String status) { Random rand = new Random(); int x = rand.nextInt(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, customlistview.class); if (status.equalsIgnoreCase("accept")) message = message + " added you as buddy"; else/*from ww w . java2 s .c o m*/ message = message + " rejected you as buddy"; PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis()); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(x, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock mWakelock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title); mWakelock.acquire(); // Timer before putting Android Device to sleep mode. Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { mWakelock.release(); } }; timer.schedule(task, 5000); }
From source file:br.org.projeto.vigilante.push.MyGcmListenerService.java
private void sendNotification(String message) { Intent intent = MainActivity_.intent(this).get(); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.app_name)).setSmallIcon(R.drawable.ic_stat_action_account_child) .setColor(getResources().getColor(R.color.colorPrimary)) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }