List of usage examples for android.app Notification setLatestEventInfo
@Deprecated public void setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent)
From source file:nl.johndekroon.dma.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. */// ww w.ja v a 2s.co m private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_stat_gcm; 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, MainActivity.class); // 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, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:vcc.mobile.pega.gcm.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from w w w . j ava 2s .c om*/ @SuppressWarnings("deprecation") private static void generateNotification(Context context, String... message) { String content = message[0]; String source = message[1]; String id = message[2]; int idInt = 0; try { idInt = Integer.valueOf(id); } catch (Exception e) { e.printStackTrace(); } int icon = R.drawable.icon_launcher; long when = System.currentTimeMillis(); String title = context.getString(R.string.app_name); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, content, when); Intent notificationIntent = new Intent(context, NotificationActivity.class); // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | // Intent.FLAG_ACTIVITY_SINGLE_TOP); notificationIntent.putExtra(NotificationActivity.PARAM_SOURCE, source); notificationIntent.putExtra(NotificationActivity.PARAM_ID, id); PendingIntent intent = PendingIntent.getActivity(context, idInt, notificationIntent, 0); notification.setLatestEventInfo(context, title, content, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(idInt, notification); }
From source file:com.afrolkin.samplepushclient.GCMIntentService.java
private static void generateNotification(Context context, String message) { int icon = R.mipmap.ic_announcement_black_48dp; long when = System.currentTimeMillis(); String title = context.getString(R.string.app_name); Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, "Push Message", when); notification.sound = soundUri;/*from ww w . j av a2s . com*/ Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.putExtra("message", message); // 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_CANCEL_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.fanfou.app.opensource.service.DownloadService.java
public static void notifyUpdate(final AppVersionInfo info, final Context context) { final String versionInfo = info.versionName; final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final Notification notification = new Notification(R.drawable.ic_notify_icon, "?" + versionInfo, System.currentTimeMillis()); final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, DownloadService.getNewVersionIntent(context, info), 0); notification.setLatestEventInfo(context, "?" + versionInfo, "", contentIntent); notification.flags |= Notification.FLAG_AUTO_CANCEL; nm.notify(2, notification);//from w ww . jav a 2 s .c om }
From source file:org.addhen.smssync.util.Util.java
/** * Show a notification/* w w w. j a va 2 s.co m*/ * * @param String * message to display * @param String * notification title */ public static void showFailNotification(Context context, String message, String notification_title) { 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()); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, baseIntent, 0); notification.setLatestEventInfo(context, notification_title, message, pendingIntent); notificationManager.notify(NOTIFY_RUNNING, notification); }
From source file:com.arisprung.tailgate.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from ww w . ja va2 s. c o m*/ private static void generateNotification(Context context, MessageBean message) { // Intent notificationIntent = new Intent(ctx, MainActivity.class); // PendingIntent contentIntent = PendingIntent.getActivity(ctx, // 10, notificationIntent, // PendingIntent.FLAG_CANCEL_CURRENT); // // NotificationManager nm = (NotificationManager) ctx // .getSystemService(Context.NOTIFICATION_SERVICE); // // Resources res = ctx.getResources(); // Notification.Builder builder = new Notification.Builder(ctx); // // Bitmap profile = TailGateUtility.getUserPic(message.getFaceID()); // // builder.setContentIntent(contentIntent) // .setSmallIcon(R.drawable.ic_launcher) // .setLargeIcon(profile) // .setTicker(res.getString(R.string.app_name)) // .setWhen(System.currentTimeMillis()) // .setAutoCancel(true) // .setContentTitle(message.getUserName()) // .setContentText(message.getMessage()); // Notification n = builder.build(); // // nm.notify(0, n); int icon = R.drawable.fanatic_icon_72px; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message.getMessage(), when); String name = message.getUserName(); Intent notificationIntent = new Intent(context, MainActivity.class); // 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, 0); notification.setLatestEventInfo(context, name, message.getMessage(), intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.vendsy.bartsy.venue.GCMIntentService.java
/** * To generate a notification to inform the user that server has sent a message. * /* w w w . java 2 s . c o m*/ * @param count * @param count */ private static void generateNotification(Context context, String message, String count) { 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, MainActivity.class); // 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, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; try { int countValue = Integer.parseInt(count); notification.number = countValue; } catch (NumberFormatException e) { e.printStackTrace(); } // // Play default notification sound notification.defaults = Notification.DEFAULT_SOUND; notificationManager.notify(0, notification); }
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 a2 s .com 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); }
From source file:com.geomoby.geodeals.DemoService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from w w w . j a v a 2s . co m*/ private static void generateNotification(Context context, String message) { if (message.length() > 0) { // Parse the GeoMoby message using the GeoMessage class try { Gson gson = new Gson(); JsonParser parser = new JsonParser(); JsonArray Jarray = parser.parse(message).getAsJsonArray(); ArrayList<GeoMessage> alerts = new ArrayList<GeoMessage>(); for (JsonElement obj : Jarray) { GeoMessage gName = gson.fromJson(obj, GeoMessage.class); alerts.add(gName); } // Prepare Notification and pass the GeoMessage to an Extra NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Intent i = new Intent(context, CustomNotification.class); i.putParcelableArrayListExtra("GeoMessage", (ArrayList<GeoMessage>) alerts); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); // Read from the /assets directory Resources resources = context.getResources(); AssetManager assetManager = resources.getAssets(); try { InputStream inputStream = assetManager.open("geomoby.properties"); Properties properties = new Properties(); properties.load(inputStream); String push_icon = properties.getProperty("push_icon"); int icon = resources.getIdentifier(push_icon, "drawable", context.getPackageName()); int not_title = resources.getIdentifier("notification_title", "string", context.getPackageName()); int not_text = resources.getIdentifier("notification_text", "string", context.getPackageName()); int not_ticker = resources.getIdentifier("notification_ticker", "string", context.getPackageName()); // Manage notifications differently according to Android version if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(icon).setContentTitle(context.getResources().getText(not_title)) .setContentText(context.getResources().getText(not_text)) .setTicker(context.getResources().getText(not_ticker)) .setContentIntent(pendingIntent).setAutoCancel(true); builder.setDefaults(Notification.DEFAULT_ALL); //Vibrate, Sound and Led // Because the ID remains unchanged, the existing notification is updated. notificationManager.notify(notifyID, builder.build()); } else { Notification notification = new Notification(icon, context.getResources().getText(not_text), System.currentTimeMillis()); //Setting Notification Flags notification.defaults |= Notification.DEFAULT_ALL; notification.flags |= Notification.FLAG_AUTO_CANCEL; //Set the Notification Info notification.setLatestEventInfo(context, context.getResources().getText(not_text), context.getResources().getText(not_ticker), pendingIntent); //Send the notification // Because the ID remains unchanged, the existing notification is updated. notificationManager.notify(notifyID, notification); } } catch (IOException e) { System.err.println("Failed to open geomoby property file"); e.printStackTrace(); } } catch (JsonParseException e) { Log.i(TAG, "This is not a GeoMoby notification"); throw new RuntimeException(e); } } }
From source file:com.rocketsingh.biker.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from w w w .ja va 2 s. c om*/ 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(); }