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.molice.oneingdufs.androidpn.Notifier.java
public Notifier(Context context) { this.context = context; this.sharedPrefs = new SharedPreferencesStorager(context); this.notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); }
From source file:io.coldstart.android.GCMIntentService.java
@Override protected void onMessage(Context arg0, Intent intent) { String ns = Context.NOTIFICATION_SERVICE; mNM = (NotificationManager) arg0.getSystemService(ns); //Log.e("GCMIntentService","onMessageonMessageonMessageonMessage"); //GCM Payload String alertCount = intent.getExtras().getString("alertCount"); String maxSeverity = intent.getExtras().getString("alertSeverity"); String alertTime = intent.getExtras().getString("alertTime"); String alertType = intent.getExtras().getString("alertType"); String payloadJSON = intent.getExtras().getString("payload"); //Stuff from the payload String hostname = "---", TrapDetails = "---", IP = "", Date = "", Uptime = "", payloadDetails = "Unknown payload"; //0 = a single alert if (alertType.equals(API.MSG_TRAP)) { if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("allowBundling", false)) { //Log.i("TRAP","Received a trap notification but I'm bundling"); return; }/*from www .j ava2 s . com*/ try { JSONObject payload = new JSONObject(payloadJSON); //Log.i("payload",payload.toString(3)); try { hostname = payload.getJSONObject("source").getString("hostname"); } catch (Exception e) { hostname = "Unknown host"; } try { //payloadDetails = payload.getJSONArray("trapdetails"); payloadDetails = payload.getString("trapdetails"); } catch (Exception e) { //e.printStackTrace(); payloadDetails = "Unknown Trap payload"; } try { IP = payload.getJSONObject("source").getString("ip"); } catch (Exception e) { IP = "127.0.0.1"; } try { Date = payload.getString("date"); } catch (Exception e) { Date = "01/01/1970"; } try { Uptime = payload.getString("uptime"); } catch (Exception e) { Uptime = ""; } } catch (Exception e) { //e.printStackTrace(); } Trap trap = new Trap(hostname, IP); trap.date = Date; trap.uptime = Uptime; trap.trap = payloadDetails; if (Build.VERSION.SDK_INT >= 16) { SendInboxStyleNotification(alertCount, alertTime, hostname, trap.getPayloadAsString()); } else { SendCombinedNotification(alertCount); } datasource = new TrapsDataSource(this); datasource.open(); datasource.addRecentTrap(trap); datasource.close(); //If the app is in the foreground we should instruct it to refresh Intent broadcast = new Intent(); broadcast.setAction(API.BROADCAST_ACTION); sendBroadcast(broadcast); } //1 = an generic notification //TODO Create generic handler //2 = batch (a bit like rate limit but on user choice) else if (alertType.equals(API.MSG_BATCH)) { //Check we are ones after a bundled alert (many people share this GCM ID) if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("allowBundling", false)) { sendBatchNotification(intent.getExtras().getString("alertCount")); } else { //Log.i("BATCHING","Batching isn't enabled at the moment"); } } //3 = Zenoss (for use with Rhybudd / coldstart HTTP API) else if (alertType.equals(API.MSG_ZENOSS)) { Intent broadcast = new Intent(); broadcast.setAction(API.ZENOSS_BROADCAST_ACTION); sendBroadcast(broadcast); } //4 = rate limit hit else if (alertType.equals(API.MSG_RATELIMIT)) { sendRateLimitNotification(intent.getExtras().getString("ratelimit")); } else { //Do nothing //TODO Log an error / inform the user they need to update? } }
From source file:de.grobox.blitzmail.SendActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // before doing anything show notification about sending process mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(this); mBuilder.setContentTitle(getString(R.string.sending_mail)).setContentText(getString(R.string.please_wait)) .setSmallIcon(R.drawable.notification_icon).setOngoing(true); // Sets an activity indicator for an operation of indeterminate length mBuilder.setProgress(0, 0, true);//from w w w . j ava 2 s . c o m // Create Pending Intent notifyIntent = new Intent(this, NotificationHandlerActivity.class); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(pendingIntent); // Issues the notification mNotifyManager.notify(0, mBuilder.build()); Properties prefs; try { prefs = getPrefs(); } catch (Exception e) { String msg = e.getMessage(); Log.i("SendActivity", "ERROR: " + msg, e); if (e.getClass().getCanonicalName().equals("java.lang.RuntimeException") && e.getCause() != null && e.getCause().getClass().getCanonicalName().equals("javax.crypto.BadPaddingException")) { msg = getString(R.string.error_decrypt); } showError(msg); return; } // get and handle Intent Intent intent = getIntent(); String action = intent.getAction(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (action.equals(Intent.ACTION_SEND)) { String text = intent.getStringExtra(Intent.EXTRA_TEXT); //String email = intent.getStringExtra(Intent.EXTRA_EMAIL); String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT); String cc = intent.getStringExtra(Intent.EXTRA_CC); String bcc = intent.getStringExtra(Intent.EXTRA_BCC); // Check for empty content if (subject == null && text != null) { // cut all characters from subject after the 128th subject = text.substring(0, (text.length() < 128) ? text.length() : 128); // remove line breaks from subject subject = subject.replace("\n", " ").replace("\r", " "); } else if (subject != null && text == null) { text = subject; } else if (subject == null && text == null) { Log.e("Instant Mail", "Did not send mail, because subject and body empty."); showError(getString(R.string.error_no_body_no_subject)); return; } // create JSON object with mail information mMail = new JSONObject(); try { mMail.put("id", String.valueOf(new Date().getTime())); mMail.put("body", text); mMail.put("subject", subject); mMail.put("cc", cc); mMail.put("bcc", bcc); } catch (JSONException e) { e.printStackTrace(); } // remember mail for later MailStorage.saveMail(this, mMail); // pass mail on to notification dialog class notifyIntent.putExtra("mail", mMail.toString()); // Start Mail Task AsyncMailTask mail = new AsyncMailTask(this, prefs, mMail); mail.execute(); } else if (action.equals("BlitzMailReSend")) { try { mMail = new JSONObject(intent.getStringExtra("mail")); } catch (JSONException e) { e.printStackTrace(); } // pass mail on to notification dialog class notifyIntent.putExtra("mail", mMail.toString()); // Start Mail Task AsyncMailTask mail = new AsyncMailTask(this, prefs, mMail); mail.execute(); } finish(); }
From source file:app.presentation.foundation.gcm.GcmReceiverBackground.java
private void showNotification(Message message, String title, String body, Application application) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(application) .setContentTitle(title).setContentText(body).setDefaults(Notification.DEFAULT_ALL) .setSmallIcon(R.mipmap.ic_launcher).setAutoCancel(true) .setContentIntent(getPendingIntentForNotification(message)); NotificationManager notificationManager = (NotificationManager) application .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(1, notificationBuilder.build()); }
From source file:com.parse.ParsePushUnityHelper.java
/** * A helper method that provides default behavior for handling ParsePushNotificationReceived. *//*from www . j av a2s. c o m*/ public static void handleParsePushNotificationReceived(Context context, String pushPayloadString) { try { JSONObject pushData = new JSONObject(pushPayloadString); if (pushData == null || (!pushData.has("alert") && !pushData.has("title"))) { return; } ManifestInfo info = new ManifestInfo(context); String title = pushData.optString("title", info.getDisplayName()); String alert = pushData.optString("alert", "Notification received."); String tickerText = title + ": " + alert; Random random = new Random(); int contentIntentRequestCode = random.nextInt(); Intent activityIntent = info.getLauncherIntent(); PendingIntent pContentIntent = PendingIntent.getActivity(context, contentIntentRequestCode, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(alert).setTicker(tickerText).setSmallIcon(info.getPushIconId()) .setContentIntent(pContentIntent).setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL); Notification notification = builder.build(); NotificationManager manager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); int notificationId = (int) System.currentTimeMillis(); try { manager.notify(notificationId, notification); } catch (SecurityException se) { // Some phones throw exception for unapproved vibration. notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND; manager.notify(notificationId, notification); } } catch (JSONException e) { // Do nothing. } }
From source file:com.prey.beta.services.PreyBetaRunnerService.java
@Override public void onDestroy() { PreyLogger.d("********************"); PreyLogger.d("PreyRunnerService is going to be destroyed"); PreyConfig preyConfig = PreyConfig.getPreyConfig(PreyBetaRunnerService.this); preyConfig.setMissing(false);/*from ww w.jav a 2 s . co m*/ NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancelAll(); ActionsController.getInstance(PreyBetaRunnerService.this).finishRunningJosb(); running = false; //PreyLogger.d("PreyRunnerService has been destroyed"); }
From source file:com.etime.TimeAlarmService.java
@Override protected void onHandleIntent(Intent intent) { try {//from w w w . j a v a 2 s . c o m nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); boolean retval; loginName = intent.getStringExtra(USERNAME); password = intent.getStringExtra(PASSWORD); LOGIN_URL = lockContext.getString(R.string.login_url); LOGIN_URL_STEP2 = lockContext.getString(R.string.login_url2); TIMECARD_URL = lockContext.getString(R.string.timecard_url); TIMESTAMP_RECORD_URL = lockContext.getString(R.string.timestamp_record_url); LOGIN_FAILED = lockContext.getString(R.string.login_failed_str); retval = login(); if (!retval) { notifyAutoClockOutFailure(); } parseTimeCard(); retval = clockOut(); if (!retval) { notifyAutoClockOutFailure(); } else { notifyAutoClockOutSuccess(); } } finally { TimeAlarmService.getLock().release(); } }
From source file:de.wikilab.android.friendica01.FileUploadService.java
private void showFailMsg(Context ctx, String txt) { NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Log.e("Andfrnd/UploadFile", "Upload FAILED: " + txt); //Instantiate the Notification: CharSequence tickerText = "Upload failed, please retry!"; Notification notification = new Notification(R.drawable.arrow_up, tickerText, System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; //Define the Notification's expanded message and Intent: Context context = getApplicationContext(); CharSequence contentTitle = "Upload failed, click to retry!"; CharSequence contentText = txt; Intent notificationIntent = new Intent(this, FriendicaImgUploadActivity.class); Bundle b = new Bundle(); b.putParcelable(Intent.EXTRA_STREAM, fileToUpload); b.putString(Intent.EXTRA_SUBJECT, subject); b.putString(EXTRA_DESCTEXT, descText); notificationIntent.putExtras(b);//from ww w . j a v a2 s .c o m PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); //Pass the Notification to the NotificationManager: mNotificationManager.notify(UPLOAD_FAILED_ID, notification); //Toast.makeText(ctx, "Upload failed, please retry:\n" + txt, Toast.LENGTH_LONG).show(); }
From source file:com.haha01haha01.harail.DatabaseDownloader.java
@Override protected void onHandleIntent(Intent workIntent) { PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, NAME); NotificationManager notifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle("HaRail GTFS Database").setContentText("Downloading file") .setSmallIcon(android.R.drawable.ic_popup_sync).setProgress(0, 0, true); notifyManager.notify(1, builder.build()); wakeLock.acquire();/*from w w w . ja v a 2s. c o m*/ try { String filename = "harail_irw_gtfs_" + Utils.getCurrentDateString() + ".zip"; File zip_file = new File( new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DOWNLOADS), filename); if (downloadFile(irw_gtfs_server, irw_gtfs_port, "anonymous", "", irw_gtfs_filename, zip_file)) { sendFinished(extractDb(zip_file, notifyManager, builder)); } else { sendFinished(false); } wakeLock.release(); } catch (IOException e) { sendFinished(false); builder.setContentText("Download failed").setSmallIcon(android.R.drawable.ic_dialog_alert) .setProgress(0, 0, false); notifyManager.notify(1, builder.build()); wakeLock.release(); } }
From source file:angeloid.dreamnarae.Boot_Script.java
@Override public void onReceive(Context c, Intent i) { boot_top = c.getString(R.string.boot_top); boot_bottom = c.getString(R.string.boot_bottom); boot_ticker = c.getString(R.string.boot_tickker); if (!(RootTools.isAccessGiven())) { Toast.makeText(c, R.string.noroottoast, Toast.LENGTH_LONG).show(); } else {/*from w w w. j a v a 2 s .co m*/ if (new File("/system/etc/dreamnarae.sh").exists()) { CommandCapture command = new CommandCapture(0, "mount -o rw,remount /system", "sh /system/etc/dreamnarae.sh", "sh /system/etc/install-recovery.sh"); NotificationManager manager = (NotificationManager) c .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder ncbuilder = new NotificationCompat.Builder(c); ncbuilder.setContentTitle(boot_top); ncbuilder.setContentText(boot_bottom); ncbuilder.setSmallIcon(R.drawable.ic_launcher); ncbuilder.setAutoCancel(true); ncbuilder.setTicker(boot_ticker); Vibrator vibe = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE); try { RootTools.getShell(true).add(command).waitForFinish(); Log.d("debug", "ok!"); vibe.vibrate(200); manager.notify(1, ncbuilder.build()); } catch (InterruptedException e) { } catch (IOException e) { } catch (TimeoutException e) { } catch (RootDeniedException e) { } } } }