List of usage examples for android.content Context NOTIFICATION_SERVICE
String NOTIFICATION_SERVICE
To view the source code for android.content Context NOTIFICATION_SERVICE.
Click Source Link
From source file:net.frygo.findmybuddy.GCMIntentService.java
private static void generateNotification(Context context, String message) { 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); notificationIntent.putExtra("alert", message); message = message + " would like to add you as friend"; 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();/*from www .ja v a2s . c o m*/ // 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:app.com.locationfetch.GeofenceTransitionsIntentService.java
private void sendNotification(String s) { Intent intent = new Intent(this, MainActivity.class); 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) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Location Push").setContentText(s) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }
From source file:ch.christofbuechi.testgcm.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); MyWrapper myWrapper = null;/*w w w. j a v a 2 s . com*/ ObjectMapper objectMapper = new ObjectMapper(); try { myWrapper = objectMapper.readValue(new String(msg), MyWrapper.class); } catch (IOException e) { e.printStackTrace(); } Log.d(this.getClass().getName(), "Message: " + myWrapper.getData().getMsg()); Log.d(this.getClass().getName(), "Message: " + myWrapper.getRegistration_id()); Log.d(this.getClass().getName(), "Message: " + myWrapper.getData().getCt()); Log.d(this.getClass().getName(), "Message: " + myWrapper.getData().getV()); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle("GCM Notification") .setStyle(new NotificationCompat.BigTextStyle().bigText(myWrapper.getData().getMsg())) .setContentText(myWrapper.getData().getMsg()); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:br.com.epitrack.healthycup.gcm.GCMIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Splash.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setOngoing(true).setContentText(msg); mBuilder.setAutoCancel(true);/*from w w w .jav a 2s. com*/ mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.example.mobileid.GcmIntentService.java
private void sendNotification(Intent intent) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Bundle extras = intent.getExtras();//from w ww .j a va2 s . c o m JSONObject gcmObj; try { gcmObj = new JSONObject(extras.getString("message")); String msg = gcmObj.getString("info"); Intent passIntent = new Intent(); passIntent.setClass(this, MainActivity.class); passIntent.putExtra("gcmMsg", gcmObj.toString()); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, passIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); if (msg.compareToIgnoreCase("websign") != 0) { // NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) mBuilder.setSmallIcon(R.drawable.ic_launcher).setContentTitle("mobileID") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); } else { // NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) mBuilder.setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Web Sign - " + gcmObj.getString("title")) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setContentText(gcmObj.getString("content")); } //default notification sound Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); //cleared after clicking mBuilder.setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.steveliedtke.gcm.example.gcm.GCMIntentService.java
public void displayNotification(final Context context, final String message, final boolean vibrationEnabled, final boolean permanentNotification) throws JSONException { // TODO rewrite this method: throw notification with message String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); int icon;//from w ww . jav a 2 s . co m CharSequence notificationText; final CharSequence contentTitle; icon = R.drawable.ic_launcher; notificationText = context.getString(R.string.new_message); contentTitle = context.getString(R.string.new_message); long when = System.currentTimeMillis(); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(icon); builder.setTicker(notificationText); builder.setWhen(when); if (message != null && message.length() > 0) { builder.setStyle( new NotificationCompat.BigTextStyle().setSummaryText(notificationText).bigText(message)); } builder.setAutoCancel(true); builder.setContentTitle(contentTitle); builder.setContentText(notificationText); final Notification notification = builder.build(); if (vibrationEnabled) { notification.defaults |= Notification.DEFAULT_VIBRATE; } mNotificationManager.notify(82917, notification); }
From source file:com.otaupdater.utils.RomInfo.java
public static void clearUpdateNotif(Context ctx) { NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(Config.ROM_NOTIF_ID);// w w w . j av a 2s. co m }
From source file:budgetworld.ru.bw.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//from ww w .j a v a 2 s . c o m */ private void sendNotification(String message) { Intent intent = new Intent(this, MainActivity.class); //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.putExtra("from notify", message); 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.ic_stat_ic_notification).setContentTitle("BudgetWorld") .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent).setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setLights(getResources().getColor(R.color.led), 2000, 2000); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.example.AllSOSservice.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), Activity.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK);/*from www .j a v a 2s .c o m*/ String message = intent.getStringExtra("message"); String email = intent.getStringExtra("email"); String latitude = intent.getStringExtra("latitude"); String longitude = intent.getStringExtra("longitude"); Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG); toast.show(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Novo Pedido de Ajuda!") .setContentText("Alguem precisa de um " + message); Intent resultIntent = null; try { if (isLoggedIn()) { resultIntent = new Intent(context, LoggedInActivity.class); } else { resultIntent = new Intent(context, LoginActivity.class); } } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } // Because clicking the notification opens a new ("special") activity, there's // no need to create an artificial back stack. PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); int mNotificationId = 001; // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Builds the notification and issues it. mNotifyMgr.notify(mNotificationId, mBuilder.build()); }
From source file:com.jieehd.villain.toolkit.stats.ReportingService.java
private void promptUser() { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent nI = new Intent(); nI.setComponent(new ComponentName(getPackageName(), AnonymousStats.class.getName())); PendingIntent pI = PendingIntent.getActivity(this, 0, nI, 0); Notification.Builder builder = new Notification.Builder(this).setAutoCancel(true) .setTicker("Annonymous Statistics").setContentIntent(pI).setWhen(0) .setContentTitle("Annonymous Statistics").setContentText("Enable Reporting"); nm.notify(1, builder.getNotification()); }