List of usage examples for android.app Notification Notification
@Deprecated public Notification(int icon, CharSequence tickerText, long when)
From source file:com.survey.android.c2dm.GcmNotificationReceiver.java
@SuppressWarnings("deprecation") private void sendNotification(Intent intent) { final String testResult = intent.getStringExtra("message"); final String surveyId = intent.getStringExtra("survey_id"); try {// ww w.j ava 2 s . com String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(ns); String mDrawableName = "c2dm_icon"; int icon = this.getResources().getIdentifier(mDrawableName, "drawable", Prefs.PACKAGE); CharSequence tickerText = "Survey notification"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); CharSequence contentTitle = "Survey notification"; int NOTIFICATION_ID = 1; Intent notificationIntent = new Intent(this, com.survey.android.view.themed.NotificationActivity.class); notificationIntent.putExtra("notification_id", NOTIFICATION_ID); notificationIntent.putExtra("survey_id", surveyId); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT + PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this, contentTitle, testResult, contentIntent); mNotificationManager.notify(NOTIFICATION_ID, notification); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.bfr.periodicquery.PeriodicQueryService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { // The intent to launch when the user clicks the expanded notification Intent launchIntent = new Intent(this, StartStopActivity.class); launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendIntent = PendingIntent.getActivity(this, 0, launchIntent, 0); // This constructor is deprecated. Use Notification.Builder instead Notification notice = new Notification(R.drawable.ic_launcher, "Periodic Query", System.currentTimeMillis()); // This method is deprecated. Use Notification.Builder instead. notice.setLatestEventInfo(this, "Periodic Query", "Periodic Query", pendIntent); notice.flags |= Notification.FLAG_NO_CLEAR; startForeground(1234, notice);//from w w w. j a v a2 s . c o m return START_STICKY; }
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();//w w w.java 2 s . 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:de.wikilab.android.friendica01.FileUploadService.java
private void showSuccessMsg(Context ctx) { NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); //Instantiate the Notification: int icon = R.drawable.arrow_up; CharSequence tickerText = "Upload succeeded!"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); notification.flags |= Notification.FLAG_AUTO_CANCEL; /*/* w w w.j a v a2s.c om*/ //TODO!!! //Define the Notification's expanded message and Intent: Context context = getApplicationContext(); CharSequence contentTitle = "Upload successful, click to show details!"; CharSequence contentText = targetFilename; Intent notificationIntent = new Intent(this, FilePreview.class); Bundle b = new Bundle(); b.putInt("cid", clipId); notificationIntent.putExtras(b); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); */ //Define the Notification's expanded message and Intent: Context context = getApplicationContext(); PendingIntent nullIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); notification.setLatestEventInfo(context, tickerText, "Click to dismiss", nullIntent); //Pass the Notification to the NotificationManager: mNotificationManager.notify(UPLOAD_SUCCESS_ID, notification); //Toast.makeText(ctx, "Upload failed, please retry:\n" + txt, Toast.LENGTH_LONG).show(); }
From source file:com.riksof.a320.c2dm.common.C2DMReceiver.java
@Override protected void onMessage(Context contxt, Intent intent) { String unValidatedURL = intent.getStringExtra("payload"); Log.w("C2DMReceiver", unValidatedURL); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); int icon = R.drawable.ic_launcher; // icon from resources CharSequence tickerText = "You got message !!!"; // ticker-text long when = System.currentTimeMillis(); // notification time Context context = getApplicationContext(); // application Context Intent notificationIntent = new Intent(this, PushEndpointDemo.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); CharSequence contentTitle = "Norification Received !"; // the next two lines initialize the Notification, using the configurations above Notification notification = new Notification(icon, tickerText, when); notification.defaults |= Notification.DEFAULT_LIGHTS; notification.ledARGB = 0xff00ff00;/*from ww w . java 2s.c o m*/ notification.ledOnMS = 300; notification.ledOffMS = 1000; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.setLatestEventInfo(context, contentTitle, unValidatedURL, contentIntent); notificationManager.notify(10001, notification); Cache.getInstance().remove(unValidatedURL); FileCache fc = new FileCache(context); fc.clear(); Log.w("C2DMReceiver", "finish"); }
From source file:menion.android.whereyougo.gui.extension.activity.CustomActivity.java
public static void setStatusbar(Activity activity) { try {/*from ww w . j ava 2 s . c om*/ NotificationManager mNotificationManager = (NotificationManager) activity .getSystemService(Context.NOTIFICATION_SERVICE); // set statusbar if (Preferences.APPEARANCE_STATUSBAR) { Context context = activity.getApplicationContext(); Intent intent = new Intent(context, menion.android.whereyougo.gui.activity.MainActivity.class); // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setAction(Intent.ACTION_MAIN); PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0); final int sdkVersion = Integer.parseInt(android.os.Build.VERSION.SDK); Notification notif = null; if (sdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) { notif = new Notification(R.drawable.ic_title_logo, A.getAppName(), System.currentTimeMillis()); notif.setLatestEventInfo(activity, A.getAppName(), "", pIntent); } else { NotificationCompat.Builder builder = new NotificationCompat.Builder(activity) .setContentTitle(A.getAppName()).setSmallIcon(R.drawable.ic_title_logo) .setContentIntent(pIntent); notif = builder.build(); } notif.flags = Notification.FLAG_ONGOING_EVENT; mNotificationManager.notify(0, notif); } else { mNotificationManager.cancel(0); } } catch (Exception e) { // Logger.e(TAG, "setStatusbar(" + activity + ")", e); } }
From source file:com.rocketsingh.biker.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*w ww .ja va2s.c o m*/ public static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MapActivity.class); notificationIntent.putExtra("fromNotification", "notification"); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; System.out.println("notification====>" + message); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; // notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0x00000000; notification.ledOnMS = 0; notification.ledOffMS = 0; notificationManager.notify(AndyConstants.NOTIFICATION_ID, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock( PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "WakeLock"); wakeLock.acquire(); wakeLock.release(); }
From source file:com.bakhtiyor.android.tumblr.TumblrService.java
private void showResultNotification(String message) { long when = System.currentTimeMillis(); Notification notification = new Notification(R.drawable.icon, APP_TITLE, when); notification.flags = Notification.FLAG_AUTO_CANCEL; Intent notificationIntent = new Intent(this, TumblrService.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(getApplicationContext(), APP_TITLE, message, contentIntent); notificationManager.notify(RESULT_NOTIFICATION_ID, notification); }
From source file:uk.co.gidley.clockRadio.RadioPlayerService.java
private void showNotification() { // In this sample, we'll use the same text for the ticker and the // expanded notification CharSequence text = getText(R.string.local_service_started); // Set the icon, scrolling text and timestamp Notification notification = new Notification(R.drawable.icon, text, System.currentTimeMillis()); // The PendingIntent to launch our activity if the user selects this // notification PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, ClockRadioActivity.class), 0);/*from w w w. jav a2 s . co m*/ // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(this, getText(R.string.local_service_label), text, contentIntent); notification.flags |= Notification.FLAG_ONGOING_EVENT; startForeground(NOTIFICATION, notification); Log.d(TAG, "Show Notification Complete"); }
From source file:com.google.android.gcm.demo.app.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *///from www . j av a 2 s . c o m private static void generateNotification(Context context, String message, String data) { int icon = R.drawable.ic_stat_gcm; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(0); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, DemoActivity.class); notificationIntent.putExtra(CommonUtilities.EXTRA_TEAM_IN_JSON, data); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags = Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }