Example usage for android.app Notification setLatestEventInfo

List of usage examples for android.app Notification setLatestEventInfo

Introduction

In this page you can find the example usage for android.app Notification setLatestEventInfo.

Prototype

@Deprecated
public void setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText,
        PendingIntent contentIntent) 

Source Link

Document

Sets the #contentView field to be a view with the standard "Latest Event" layout.

Usage

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  . ja v  a  2s .co  m

    return START_STICKY;
}

From source file:de.incoherent.suseconferenceclient.app.AlarmReceiver.java

@SuppressWarnings({ "deprecation" })
@Override/*from w w w.j  a va  2s.  c  o  m*/
public void onReceive(Context context, Intent intent) {
    Intent notificationIntent = new Intent(context, HomeActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    String title = intent.getStringExtra("title");
    String room = intent.getStringExtra("room");
    String time = intent.getStringExtra("timetext");
    String message = time + ", " + room;

    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.ic_launcher, null, System.currentTimeMillis());
    notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = context.getResources().getColor(R.color.dark_suse_green);
    notification.ledOffMS = 1000;
    notification.ledOnMS = 300;
    notification.setLatestEventInfo(context, title, message, contentIntent);
    manager.notify(13572, notification);
}

From source file:free.yhc.netmbuddy.model.NotiManager.java

private Notification buildNotificationGB(NotiType ntype, CharSequence videoTitle) {
    Intent intent = new Intent(Utils.getAppContext(), NotiManager.NotiIntentReceiver.class);
    intent.setAction(NOTI_INTENT_DELETE);
    PendingIntent piDelete = PendingIntent.getBroadcast(Utils.getAppContext(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    intent = new Intent(Utils.getAppContext(), NotiManager.NotiIntentReceiver.class);
    intent.setAction(NOTI_INTENT_ACTION);
    intent.putExtra("type", ntype.name());
    PendingIntent piContent = PendingIntent.getBroadcast(Utils.getAppContext(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    /*/*w w  w .  ja  va  2 s.c o  m*/
     * NOTE
     * Below way is deprecated but works well better than using recommended way - notification builder.
     * (See commends below about using builder)
     */
    Notification n = new Notification(ntype.getIcon(), null, System.currentTimeMillis());
    n.setLatestEventInfo(Utils.getAppContext(), Utils.getResString(R.string.app_name), videoTitle, piContent);
    n.deleteIntent = piDelete;
    n.flags = 0;

    return n;
    /* Below code generates "java.lang.NoClassDefFoundError : android.support.v4.app.NotificationCompat$Builder"
     * So, comment out!
     * (Damn Android!
     *
    NotificationCompat.Builder nbldr = new NotificationCompat.Builder(Utils.getAppContext());
    nbldr.setSmallIcon(ntype.getIcon())
     .setTicker(null)
     .setContentTitle(title)
     .setContentText(desc)
     .setAutoCancel(true)
     .setContentIntent(piContent)
     .setDeleteIntent(piDelete);
    return nbldr.build();
    */
}

From source file:org.droidkit.app.UpdateService.java

private void notifyUser(String json) {
    Intent intent = new Intent(this, UpdateActivity.class);
    intent.putExtra("json", json);

    String desc = "Update available for " + getString(getApplicationInfo().labelRes);

    PendingIntent pending = PendingIntent.getActivity(this, 0, intent, 0);
    Notification n = new Notification(android.R.drawable.stat_sys_download_done, "Update available",
            System.currentTimeMillis());
    n.setLatestEventInfo(this, "Update Available", desc, pending);

    mNotificationManager.notify("Update Available", UPDATE_SERVICE_ID, n);
}

From source file:com.networkmanagerapp.JSONBackgroundDownloaderService.java

/**
 * Displays a notification in the system notification area
 *//*from   w ww. java2 s.c  o  m*/
private void showNotification() {
    CharSequence text = getText(R.string.download_service_started);
    Notification notification = new Notification(R.drawable.ic_stat_networkman, text,
            System.currentTimeMillis());
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, NetworkManagerMainActivity.class), 0);
    notification.setLatestEventInfo(this, text, text, contentIntent);
    mNM.notify(R.string.download_service_started, notification);
}

From source file:com.etime.TimeAlarmService.java

/**
 * Send a notification to the user with the message 'notificationString'
 * @param notifcationString    The message to notify the user with.
 *///  w  ww  .jav a  2s.  c o m
private void notification(String notifcationString) {
    CharSequence from = "ETime";
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
    Notification notif = new Notification(R.drawable.icon, notifcationString, System.currentTimeMillis());

    notif.flags |= Notification.DEFAULT_LIGHTS;
    notif.defaults |= Notification.DEFAULT_VIBRATE;

    notif.setLatestEventInfo(this, from, notifcationString, contentIntent);
    nm.notify("ETime", APP_ID, notif);
}

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:com.freshplanet.nativeExtensions.C2DMBroadcastReceiver.java

/**
 * Get the parameters from the message and create a notification from it.
 * @param context/*from w  w w  .j a  v  a  2  s.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:uk.co.jarofgreen.cityoutdoors.Service.SendFeatureContentOrReportService.java

protected void onHandleIntent(Intent intent) {

    OurApplication ourApp = (OurApplication) getApplication();

    if (ourApp.hasMoreToUpload()) {
        BaseUploadContentOrReport upload = ourApp.getNextToUpload();

        int featureID = upload.hasFeatureID() ? upload.getFeatureID() : -1;

        // ---------- Start Ongoing Notification
        int icon = R.drawable.notification;
        long when = System.currentTimeMillis();
        Notification notification = new Notification(icon, "Sending", when);

        Intent notificationIntent = new Intent(this, SendFeatureContentOrReportProgressActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

        notification.setLatestEventInfo(getApplicationContext(),
                getString(R.string.send_feature_content_or_report_service_notification_content_title),
                getString(R.string.send_feature_content_or_report_service_notification_content_text),
                contentIntent);//w ww  .  j a  va  2 s. co  m
        notification.flags = Notification.DEFAULT_SOUND;
        notification.flags |= Notification.DEFAULT_VIBRATE;
        notification.flags |= Notification.DEFAULT_LIGHTS;
        notification.flags |= Notification.FLAG_ONGOING_EVENT;

        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(SendFeatureContentOrReportService.NOTIFICATION_ID, notification);

        //------------ Send
        if (upload instanceof UploadFeatureContent) {
            sendFeatureContent((UploadFeatureContent) upload);
        } else if (upload instanceof UploadFeatureReport) {
            sendFeatureReport((UploadFeatureReport) upload);
        }

        //----------- Remove from que
        ourApp.removeUploadFromQue(upload);

        // ---------- End Ongoing Notification
        if (!ourApp.hasMoreToUpload()) {
            mNotificationManager.cancel(SendFeatureContentOrReportService.NOTIFICATION_ID);
        }

    }

}

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);/*  w  w  w. j a va 2  s  .  co m*/
    mNM.notify(NOTIFICATION, notification);

}