List of usage examples for android.app Notification Notification
@Deprecated public Notification(int icon, CharSequence tickerText, long when)
From source file:foam.zizim.android.BoskoiService.java
private void showNotification(String tickerText) { // This is what should be launched if the user selects our notification. Intent baseIntent = new Intent(this, IncidentsTab.class); baseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, baseIntent, 0); // choose the ticker text newBoskoiReportNotification = new Notification(R.drawable.favicon, tickerText, System.currentTimeMillis()); newBoskoiReportNotification.contentIntent = contentIntent; newBoskoiReportNotification.flags = Notification.FLAG_AUTO_CANCEL; newBoskoiReportNotification.defaults = Notification.DEFAULT_ALL; newBoskoiReportNotification.setLatestEventInfo(this, TAG, tickerText, contentIntent); if (ringtone) { // set the ringer Uri ringURI = Uri.fromFile(new File("/system/media/audio/ringtones/ringer.mp3")); newBoskoiReportNotification.sound = ringURI; }/*ww w . j a v a 2 s . co m*/ if (vibrate) { double vibrateLength = 100 * Math.exp(0.53 * 20); long[] vibrate = new long[] { 100, 100, (long) vibrateLength }; newBoskoiReportNotification.vibrate = vibrate; if (flashLed) { int color = Color.BLUE; newBoskoiReportNotification.ledARGB = color; } newBoskoiReportNotification.ledOffMS = (int) vibrateLength; newBoskoiReportNotification.ledOnMS = (int) vibrateLength; newBoskoiReportNotification.flags = newBoskoiReportNotification.flags | Notification.FLAG_SHOW_LIGHTS; } mNotificationManager.notify(NOTIFICATION_ID, newBoskoiReportNotification); }
From source file:com.maass.android.imgur_uploader.ImgurUpload.java
private void handleResponse() { Log.i(this.getClass().getName(), "in handleResponse()"); // close progress notification mNotificationManager.cancel(NOTIFICATION_ID); String notificationMessage = getString(R.string.upload_success); // notification intent with result final Intent notificationIntent = new Intent(getBaseContext(), ImageDetails.class); if (mImgurResponse == null) { notificationMessage = getString(R.string.connection_failed); } else if (mImgurResponse.get("error") != null) { notificationMessage = getString(R.string.unknown_error) + mImgurResponse.get("error"); } else {/*w w w . jav a2 s.co m*/ // create thumbnail if (mImgurResponse.get("image_hash").length() > 0) { createThumbnail(imageLocation); } // store result in database final HistoryDatabase histData = new HistoryDatabase(getBaseContext()); final SQLiteDatabase data = histData.getWritableDatabase(); final HashMap<String, String> dataToSave = new HashMap<String, String>(); dataToSave.put("delete_hash", mImgurResponse.get("delete_hash")); dataToSave.put("image_url", mImgurResponse.get("original")); final Uri imageUri = Uri .parse(getFilesDir() + "/" + mImgurResponse.get("image_hash") + THUMBNAIL_POSTFIX); dataToSave.put("local_thumbnail", imageUri.toString()); dataToSave.put("upload_time", "" + System.currentTimeMillis()); for (final Map.Entry<String, String> entry : dataToSave.entrySet()) { final ContentValues content = new ContentValues(); content.put("hash", mImgurResponse.get("image_hash")); content.put("key", entry.getKey()); content.put("value", entry.getValue()); data.insert("imgur_history", null, content); } //set intent to go to image details notificationIntent.putExtra("hash", mImgurResponse.get("image_hash")); notificationIntent.putExtra("image_url", mImgurResponse.get("original")); notificationIntent.putExtra("delete_hash", mImgurResponse.get("delete_hash")); notificationIntent.putExtra("local_thumbnail", imageUri.toString()); data.close(); histData.close(); // if the main activity is already open then refresh the gridview sendBroadcast(new Intent(BROADCAST_ACTION)); } //assemble notification final Notification notification = new Notification(R.drawable.icon, notificationMessage, System.currentTimeMillis()); notification.setLatestEventInfo(this, getString(R.string.app_name), notificationMessage, PendingIntent .getActivity(getBaseContext(), 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT)); notification.flags |= Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:com.freshplanet.nativeExtensions.C2DMBroadcastReceiver.java
/** * Get the parameters from the message and create a notification from it. * @param context//from w ww .j a v a2s . c o m * @param intent */ public void handleMessage(Context context, Intent intent) { try { registerResources(context); extractColors(context); FREContext ctxt = C2DMExtension.context; NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // icon is required for notification. // @see http://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html int icon = notificationIcon; long when = System.currentTimeMillis(); // json string String parameters = intent.getStringExtra("parameters"); String facebookId = null; JSONObject object = null; if (parameters != null) { try { object = (JSONObject) new JSONTokener(parameters).nextValue(); } catch (Exception e) { Log.d(TAG, "cannot parse the object"); } } if (object != null && object.has("facebookId")) { facebookId = object.getString("facebookId"); } CharSequence tickerText = intent.getStringExtra("tickerText"); CharSequence contentTitle = intent.getStringExtra("contentTitle"); CharSequence contentText = intent.getStringExtra("contentText"); Intent notificationIntent = new Intent(context, Class.forName(context.getPackageName() + ".AppEntry")); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Notification notification = new Notification(icon, tickerText, when); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); RemoteViews contentView = new RemoteViews(context.getPackageName(), customLayout); contentView.setTextViewText(customLayoutTitle, contentTitle); contentView.setTextViewText(customLayoutDescription, contentText); contentView.setTextColor(customLayoutTitle, notification_text_color); contentView.setFloat(customLayoutTitle, "setTextSize", notification_title_size_factor * notification_text_size); contentView.setTextColor(customLayoutDescription, notification_text_color); contentView.setFloat(customLayoutDescription, "setTextSize", notification_description_size_factor * notification_text_size); if (facebookId != null) { Log.d(TAG, "bitmap not null"); CreateNotificationTask cNT = new CreateNotificationTask(); cNT.setParams(customLayoutImageContainer, NotifId, nm, notification, contentView); String src = "http://graph.facebook.com/" + facebookId + "/picture?type=normal"; URL url = new URL(src); cNT.execute(url); } else { Log.d(TAG, "bitmap null"); contentView.setImageViewResource(customLayoutImageContainer, customLayoutImage); notification.contentView = contentView; nm.notify(NotifId, notification); } NotifId++; if (ctxt != null) { parameters = parameters == null ? "" : parameters; ctxt.dispatchStatusEventAsync("COMING_FROM_NOTIFICATION", parameters); } } catch (Exception e) { Log.e(TAG, "Error activating application:", e); } }
From source file:de.taxilof.UulmLoginAgent.java
/** * notify the User in Statusbar//from w w w . j a v a2 s .c o m */ private void notify(String subject, String message, boolean errorIcon) { // build notification with notifyString Notification notifyDetails; mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (errorIcon) { notifyDetails = new Notification(R.drawable.icon_red, subject, System.currentTimeMillis()); } else { notifyDetails = new Notification(R.drawable.icon, subject, System.currentTimeMillis()); } PendingIntent myIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); notifyDetails.setLatestEventInfo(context, subject, message, myIntent); notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails); }
From source file:org.yaaic.irc.IRCService.java
/** * Handle command// w w w . j a v a 2 s . co m * * @param intent */ private void handleCommand(Intent intent) { if (ACTION_FOREGROUND.equals(intent.getAction())) { if (foreground) { return; // XXX: We are already in foreground... } foreground = true; // Set the icon, scrolling text and timestamp notification = new Notification(R.drawable.ic_notification, getText(R.string.notification_running), System.currentTimeMillis()); // The PendingIntent to launch our activity if the user selects this notification Intent notifyIntent = new Intent(this, MainActivity.class); notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0); notification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_notification) .setContentTitle(getText(R.string.app_name)) .setContentText(getText(R.string.notification_not_connected)) .setWhen(System.currentTimeMillis()).setContentIntent(contentIntent) .setPriority(NotificationCompat.PRIORITY_MIN).setCategory(NotificationCompat.CATEGORY_PROGRESS) .build(); startForegroundCompat(FOREGROUND_NOTIFICATION, notification); } else if (ACTION_BACKGROUND.equals(intent.getAction()) && !foreground) { stopForegroundCompat(FOREGROUND_NOTIFICATION); } else if (ACTION_ACK_NEW_MENTIONS.equals(intent.getAction())) { ackNewMentions(intent.getIntExtra(EXTRA_ACK_SERVERID, -1), intent.getStringExtra(EXTRA_ACK_CONVTITLE)); } }
From source file:com.mutu.gpstracker.streaming.CustomUpload.java
private void notifyError(Context context, Exception e) { Log.e(TAG, "Custom upload failed", e); String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); int icon = R.drawable.ic_maps_indicator_current_position; CharSequence tickerText = context.getText(R.string.customupload_failed); long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); Context appContext = context.getApplicationContext(); CharSequence contentTitle = tickerText; CharSequence contentText = e.getMessage(); Intent notificationIntent = new Intent(context, CustomUpload.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(appContext, contentTitle, contentText, contentIntent); notification.flags = Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:com.alphabetbloc.accessmrs.services.RefreshDataService.java
private void showNotification() { mNM = (NotificationManager) App.getApp().getSystemService(NOTIFICATION_SERVICE); CharSequence text = App.getApp().getText(R.string.ss_service_started); Notification notification = new Notification(R.drawable.icon, text, System.currentTimeMillis()); PendingIntent contentIntent = PendingIntent.getActivity(App.getApp(), 0, new Intent(App.getApp(), DashboardActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK); notification.setLatestEventInfo(App.getApp(), App.getApp().getText(R.string.ss_service_label), text, contentIntent);//from w w w .ja va 2 s . c o m mNM.notify(NOTIFICATION, notification); }
From source file:com.putlocker.upload.DownloadService.java
/** * @param job The job to notify about/*from w w w. j a v a 2 s . c o m*/ * @param context The context to use * Show a notification while this service is running. */ public Notification createDownloadNotification(PutlockerUpDownloadJob job, Context context, int progress) { CharSequence text; if (job.getJobType() == PutlockerUpDownloadJob.DOWNLOAD_JOB) { text = context.getText(R.string.remote_service_started); } else { text = context.getText(R.string.service_upload_started); } PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, PutlockerTransferList.class), 0); // Set the icon, scrolling text and timestamp Notification notification = new Notification(R.drawable.ic_launcher, text, System.currentTimeMillis()); notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT; notification.contentView = new RemoteViews(context.getApplicationContext().getPackageName(), R.layout.download_progress); notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.ic_launcher); if (job.getJobType() == PutlockerUpDownloadJob.DOWNLOAD_JOB) { if (FileFactory.typeFromFileName(job.getName()) == FileType.FILE_TYPE_VIDEO) { notification.contentIntent = PendingIntent.getActivity(this, 0, getIntentForJob((PutlockerDownloadJob) job), Intent.FLAG_ACTIVITY_NEW_TASK); } else { notification.contentIntent = contentIntent; } notification.contentView.setTextViewText(R.id.status_text, context.getString(R.string.download_started, job.getName())); } else { notification.contentView.setTextViewText(R.id.status_text, context.getString(R.string.upload_started, job.getName())); notification.contentIntent = contentIntent; } notification.contentView.setProgressBar(R.id.status_progress, 100, progress, false); return notification; }
From source file:org.addhen.smssync.util.Util.java
/** * Show notification//www. j a va 2s . c o m */ public static void showNotification(Context context) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Intent baseIntent = new Intent(context, MessagesTabActivity.class); baseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Notification notification = new Notification(R.drawable.icon, context.getString(R.string.status), System.currentTimeMillis()); notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, baseIntent, 0); notification.setLatestEventInfo(context, context.getString(R.string.app_name), context.getString(R.string.notification_summary), pendingIntent); notificationManager.notify(NOTIFY_RUNNING, notification); }
From source file:com.sublimis.urgentcallfilter.Magic.java
@SuppressWarnings("deprecation") private void notification() { if (MyPreference.isNotifications()) { if (mContext != null) { NotificationManager notificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager != null) { Notification notification = new Notification(R.drawable.icon, null, System.currentTimeMillis()); Intent notificationIntent = new Intent(mContext, ActivityMain.class); if (notification != null && notificationIntent != null) { notificationIntent.setFlags(notificationIntent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(mContext, mContext.getResources().getString(R.string.notification_title), mContext.getResources().getString(R.string.notification_text), pendingIntent); notificationManager.notify(0, notification); }//from w ww .j a va 2 s .c om } } } }