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:com.otaupdater.utils.KernelInfo.java
public void showUpdateNotif(Context ctx) { Intent mainInent = new Intent(ctx, TabDisplay.class); mainInent.setAction(TabDisplay.KERNEL_NOTIF_ACTION); this.addToIntent(mainInent); PendingIntent mainPIntent = PendingIntent.getActivity(ctx, 0, mainInent, PendingIntent.FLAG_CANCEL_CURRENT); Intent dlInent = new Intent(ctx, DownloadReceiver.class); dlInent.setAction(DownloadReceiver.DL_KERNEL_ACTION); this.addToIntent(dlInent); PendingIntent dlPIntent = PendingIntent.getBroadcast(ctx, 0, dlInent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx); builder.setContentIntent(mainPIntent); builder.setContentTitle(ctx.getString(R.string.notif_source)); builder.setContentText(ctx.getString(R.string.notif_text_kernel)); builder.setTicker(ctx.getString(R.string.notif_text_kernel)); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(R.drawable.updates); builder.setStyle(new NotificationCompat.BigTextStyle().bigText(changelog)); builder.setPriority(NotificationCompat.PRIORITY_LOW); builder.addAction(R.drawable.ic_download_default, ctx.getString(R.string.notif_download), dlPIntent); NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(Config.KERNEL_NOTIF_ID, builder.build()); }
From source file:com.cyanogenmod.settings.device.LtoDownloadService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (mTask != null && mTask.getStatus() != AsyncTask.Status.FINISHED) { if (ALOGV) Log.v(TAG, "LTO download is still active, not starting new download"); return START_REDELIVER_INTENT; }//from www . j a va 2 s .c om boolean forceDownload = intent.getBooleanExtra(EXTRA_FORCE_DOWNLOAD, false); if (!shouldDownload(forceDownload)) { Log.d(TAG, "Service started, but shouldn't download ... stopping"); stopSelf(); return START_NOT_STICKY; } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); String type = prefs.getString(KEY_FILE_TYPE, FILE_TYPE_DEFAULT); String uri = String.format(LTO_SOURCE_URI_PATTERN, type); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mTask = new LtoDownloadTask(uri, LTO_DESTINATION_FILE); mTask.execute(); return START_REDELIVER_INTENT; }
From source file:org.sigimera.app.android.GCMIntentService.java
@Override protected final void onMessage(final Context context, final Intent message) { final Intent msg = message; this.mainThreadHandler.post(new Runnable() { public void run() { ApplicationController controller = ApplicationController.getInstance(); controller.init(getApplicationContext(), getSharedPreferences(Constants.PREFS_NAME, 0), null); String authToken = controller.getSharedPreferences().getString("auth_token", null); final String type = msg.getStringExtra("sig_message_type"); if (type.equalsIgnoreCase("NEW_CRISIS")) { /**//from w w w . ja v a2 s .c o m * XXX: Blocks UI: Shift this code into a separate * background thread */ Crisis crisis = PersistanceController.getInstance().getCrisis(authToken, msg.getStringExtra("crisis_id")); StringBuffer message = new StringBuffer(); if (crisis != null) { message.append(crisis.getID()); message.append(" was stored successfully!"); } else { message.append("Not able to get crisis!"); } Toast.makeText(getApplicationContext(), message.toString(), Toast.LENGTH_LONG).show(); } else if (type.equalsIgnoreCase("PING")) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); Intent notificationIntent = new Intent(); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new NotificationCompat.Builder(getApplicationContext()) .setContentTitle("Sigimera PING!") .setContentText("Congratulations, push notifcation received!") .setSmallIcon(R.drawable.sigimera_logo).setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL).setContentIntent(contentIntent).build(); mNotificationManager.notify(Constants.PING_ID, notification); } else if (type.equalsIgnoreCase("CRISIS_ALERT")) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); /** * XXX: Not working with random ID. That makes always the * latest notification clickable, but not the older ones. */ int notificationID = new Random().nextInt(); Intent notificationIntent = new Intent(getApplicationContext(), CrisisAlertActivity.class); notificationIntent.putExtra("notification_id", notificationID); notificationIntent.putExtra("crisis_id", msg.getStringExtra("crisis_id")); notificationIntent.putExtra("crisis_type", msg.getStringExtra("crisis_type")); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new NotificationCompat.Builder(getApplicationContext()) .setContentTitle("CRISIS ALERT!") .setContentText("Crisis found: " + msg.getStringExtra("crisis_id")) .setSmallIcon(R.drawable.alert_red).setOngoing(true).setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL).setContentIntent(contentIntent).build(); mNotificationManager.notify(notificationID, notification); } else if (type.equalsIgnoreCase("SHARED_CRISIS")) { Intent intent = new Intent(GCMIntentService.this, CrisisActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(Constants.CRISIS_ID, msg.getStringExtra("crisis_id")); intent.putExtra(Constants.WINDOW_TYPE, Constants.WINDOW_TYPE_SHARED_CRISIS); startActivity(intent); } else if (type.equalsIgnoreCase("UNREGISTER_DEVICE")) { GCMRegistrar.unregister(ApplicationController.getInstance().getApplicationContext()); } else if (type.equalsIgnoreCase("REFRESH")) { LocationUpdaterHttpHelper locUpdater = new LocationUpdaterHttpHelper(); Location loc = LocationController.getInstance().getLastKnownLocation(); if (loc != null) { String latitude = loc.getLatitude() + ""; String longitude = loc.getLongitude() + ""; if (authToken != null) { locUpdater.execute(authToken, latitude, longitude); } } else { // TODO: Notify the user that the update location flow // has not worked. } } } }); }
From source file:com.plugin.cordova.StatusBarNotification.java
public void showNotification(CharSequence tag, CharSequence contentTitle, CharSequence contentText, int flag) { String ns = Context.NOTIFICATION_SERVICE; context = cordova.getActivity().getApplicationContext(); mNotificationManager = (NotificationManager) context.getSystemService(ns); Notification noti = StatusNotificationIntent.buildNotification(context, tag, contentTitle, contentText, flag);/*from ww w. j av a2 s . c o m*/ MY_NOTIFICATION_ID++; mNotificationManager.notify(MY_NOTIFICATION_ID, noti); }
From source file:ca.rmen.android.networkmonitor.app.service.NetMonNotification.java
public static void dismissFailedTestNotification(Context context) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(NOTIFICATION_ID_FAILED_TEST); }
From source file:be.ppareit.swiftp.gui.FsNotification.java
private void clearNotification(Context context) { Cat.d("Clearing the notifications"); String ns = Context.NOTIFICATION_SERVICE; NotificationManager nm = (NotificationManager) context.getSystemService(ns); nm.cancelAll();/*from w w w . j a va 2 s . c om*/ Cat.d("Cleared notification"); }
From source file:com.fastbootmobile.rssdemo.PushReceiver.java
@Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "ACTION : " + intent.getAction()); // Debug log the intent "action" // Get the shared preferences for OwnPush keys SharedPreferences pref = context.getApplicationContext().getSharedPreferences(OwnPushClient.PREF_PUSH, Context.MODE_PRIVATE); if (intent.getAction().equals(OwnPushClient.INTENT_RECEIVE)) { // This is a push message Log.d(TAG, "Decrypt : " + intent.getExtras().getString(OwnPushClient.EXTRA_DATA)); OwnPushCrypto fp = new OwnPushCrypto(); // Create a crypto object for decrypt // Get the app key pair from shared preferences (these have been confirmed by the register intent) OwnPushCrypto.AppKeyPair keys = fp.getKey(pref.getString(OwnPushClient.PREF_PUBLIC_KEY, ""), pref.getString(OwnPushClient.PREF_PRIVATE_KEY, "")); // Decrypt the message from the intent extra data String msg = fp.decryptFromIntent(intent.getExtras(), BuildConfig.APP_PUBLIC_KEY, keys); JSONObject jObj;//from w ww .jav a 2 s. com if (msg != null) { Log.e(TAG, "RSS : " + msg); try { // Decode the JOSN data in the message jObj = new JSONObject(msg); Intent i = new Intent(Intent.ACTION_VIEW); // Create the intent i.setData(Uri.parse(jObj.getString("link"))); // Set the data using URI (these are web links) // Convert to pending intent PendingIntent pIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), i, 0); // Create the notification Notification n = new Notification.Builder(context.getApplicationContext()) .setContentTitle("OwnPush RSS") // Main Title .setContentText(jObj.getString("title")) // Set content .setContentIntent(pIntent) // Add the pending intent .setSmallIcon(R.drawable.ic_done).setAutoCancel(true) // Remove notification if opened .build(); n.defaults |= Notification.DEFAULT_SOUND; // Make some noise on push // Get the notification manager and display notification NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notification_num, n); // Increase the notification counter by 1 notification_num++; } catch (Exception e) { return; } } } }
From source file:com.example.pushtester.GcmIntentService.java
private void sendNotification(String msg) { Log.i(TAG, "sendNotification:" + msg); mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("GCM Notification") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.carpool.dj.carpool.model.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setContentTitle("GCM Notification").setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setContentText(msg);/*w ww . ja va2s . c o m*/ mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.jiee.smartplug.services.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from w w w. j a va 2 s . co m*/ */ private void sendNotification(String message) { System.out.println(message); NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notify = new Notification(R.drawable.svc_0_small_off, "title", System.currentTimeMillis()); PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0); notify.setLatestEventInfo(getApplicationContext(), "Subject", message, pending); notif.notify(0, notify); // 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.ic_stat_ic_notification) // .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()); }