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.mozilla.gecko.updater.UpdateService.java

private void startUpdate(int flags) {
    setLastAttemptDate();/*  w w w  .jav  a  2 s .  c  om*/

    NetworkInfo netInfo = mConnectivityManager.getActiveNetworkInfo();
    if (netInfo == null || !netInfo.isConnected()) {
        Log.i(LOGTAG, "not connected to the network");
        registerForUpdates(true);
        sendCheckUpdateResult(CheckUpdateResult.NOT_AVAILABLE);
        return;
    }

    registerForUpdates(false);

    UpdateInfo info = findUpdate(hasFlag(flags, UpdateServiceHelper.FLAG_REINSTALL));
    boolean haveUpdate = (info != null);

    if (!haveUpdate) {
        Log.i(LOGTAG, "no update available");
        sendCheckUpdateResult(CheckUpdateResult.NOT_AVAILABLE);
        return;
    }

    Log.i(LOGTAG, "update available, buildID = " + info.buildID);

    AutoDownloadPolicy policy = getAutoDownloadPolicy();

    // We only start a download automatically if one of following criteria are met:
    //
    // - We have a FORCE_DOWNLOAD flag passed in
    // - The preference is set to 'always'
    // - The preference is set to 'wifi' and we are using a non-metered network (i.e. the user
    //   is OK with large data transfers occurring)
    //
    boolean shouldStartDownload = hasFlag(flags, UpdateServiceHelper.FLAG_FORCE_DOWNLOAD)
            || policy == AutoDownloadPolicy.ENABLED || (policy == AutoDownloadPolicy.WIFI
                    && !ConnectivityManagerCompat.isActiveNetworkMetered(mConnectivityManager));

    if (!shouldStartDownload) {
        Log.i(LOGTAG, "not initiating automatic update download due to policy " + policy.toString());
        sendCheckUpdateResult(CheckUpdateResult.AVAILABLE);

        // We aren't autodownloading here, so prompt to start the update
        Notification notification = new Notification(R.drawable.ic_status_logo, null,
                System.currentTimeMillis());

        Intent notificationIntent = new Intent(UpdateServiceHelper.ACTION_DOWNLOAD_UPDATE);
        notificationIntent.setClass(this, UpdateService.class);

        PendingIntent contentIntent = PendingIntent.getService(this, 0, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        notification.flags = Notification.FLAG_AUTO_CANCEL;

        notification.setLatestEventInfo(this, getResources().getString(R.string.updater_start_title),
                getResources().getString(R.string.updater_start_select), contentIntent);

        mNotificationManager.notify(NOTIFICATION_ID, notification);

        return;
    }

    File pkg = downloadUpdatePackage(info, hasFlag(flags, UpdateServiceHelper.FLAG_OVERWRITE_EXISTING));
    if (pkg == null) {
        sendCheckUpdateResult(CheckUpdateResult.NOT_AVAILABLE);
        return;
    }

    Log.i(LOGTAG, "have update package at " + pkg);

    saveUpdateInfo(info, pkg);
    sendCheckUpdateResult(CheckUpdateResult.DOWNLOADED);

    if (mApplyImmediately) {
        applyUpdate(pkg);
    } else {
        // Prompt to apply the update
        Notification notification = new Notification(R.drawable.ic_status_logo, null,
                System.currentTimeMillis());

        Intent notificationIntent = new Intent(UpdateServiceHelper.ACTION_APPLY_UPDATE);
        notificationIntent.setClass(this, UpdateService.class);
        notificationIntent.putExtra(UpdateServiceHelper.EXTRA_PACKAGE_PATH_NAME, pkg.getAbsolutePath());

        PendingIntent contentIntent = PendingIntent.getService(this, 0, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        notification.flags = Notification.FLAG_AUTO_CANCEL;

        notification.setLatestEventInfo(this, getResources().getString(R.string.updater_apply_title),
                getResources().getString(R.string.updater_apply_select), contentIntent);

        mNotificationManager.notify(NOTIFICATION_ID, notification);
    }
}

From source file:com.hhunj.hhudata.ForegroundService.java

void handleCommand(Intent intent) {
    if (intent == null) {
        return;//  ww  w.ja  v a 2  s  . c o m
    }
    if (ACTION_FOREGROUND.equals(intent.getAction())) {
        // In this sample, we'll use the same text for the ticker and the
        // expanded notification
        CharSequence text = getText(R.string.foreground_service_started);

        // Set the icon, scrolling text and timestamp
        Notification notification = new Notification(R.drawable.stat_sample, text, System.currentTimeMillis());

        // The PendingIntent to launch our activity if the user selects this
        // notification
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainTab.class), 0);//

        // Set the info for the views that show in the notification panel.
        notification.setLatestEventInfo(this, getText(R.string.local_service_label), text, contentIntent);

        startForegroundCompat(R.string.foreground_service_started, notification);

    }
    /*
     * else if (ACTION_BACKGROUND.equals(intent.getAction())) {
     * stopForegroundCompat(R.string.foreground_service_started); }
     */

}

From source file:com.paywith.ibeacon.service.IBeaconService.java

protected void generateNotification(String title, String merchanttext, String murl, String location_id) {

    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

    Builder mNotifyBuilder = new NotificationCompat.Builder(this);

    //int icon = R.drawable.ic_launcher;
    //CharSequence tickerText = "PayWith";
    //long when = System.currentTimeMillis();

    //@SuppressWarnings("deprecation")
    //Notification notification = new Notification(icon,
    //        tickerText, when);

    mNotifyBuilder.setContentText(merchanttext).setContentTitle(title).setSmallIcon(R.drawable.ic_launcher);//logo

    //notification.flags |= Notification.FLAG_AUTO_CANCEL;
    Context context = getApplicationContext();
    Intent notificationIntent = new Intent("android.intent.category.LAUNCHER");
    //CharSequence contentTitle = title;
    //CharSequence contentText = merchanttext;

    notificationIntent.putExtra("OpenUrl", murl);
    notificationIntent.putExtra("MerchantName", merchanttext);
    notificationIntent.setClassName("com.paywith.paywith", "com.paywith.paywith.MainActivity");

    //PendingIntent contentIntent = PendingIntent
    //         .getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

    //notification.setLatestEventInfo(context, contentTitle,
    //        contentText, contentIntent);

    //mNotificationManager.notify(ongoing_notification_id, notification);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
    // PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT

    // this gives us flexibility to add vibration and sound etc:
    Notification note = mNotifyBuilder.build();

    // THIS line is what makes the notification tappable to launch app and generate mCard payment:
    note.setLatestEventInfo(context, title, merchanttext, contentIntent);

    // make phone vibrate and make sound on notification:
    note.defaults |= Notification.DEFAULT_VIBRATE;
    note.defaults |= Notification.DEFAULT_SOUND;

    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    //Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP

    note.flags |= Notification.FLAG_AUTO_CANCEL;
    // Because the ID remains unchanged, the existing notification is updated.
    mNotificationManager.notify(ongoing_notification_id, note);
    //Log.e("notification","sent");
}

From source file:com.akop.bach.service.XboxLiveServiceClient.java

private void notifyMessages(XboxLiveAccount account, long[] unreadMessages, List<Long> lastUnreadList) {
    NotificationManager mgr = getNotificationManager();
    Context context = getContext();

    int notificationId = 0x1000000 | ((int) account.getId() & 0xffffff);

    if (App.getConfig().logToConsole()) {
        String s = "";
        for (Object unr : lastUnreadList)
            s += unr.toString() + ",";

        App.logv("Currently unread (%d): %s", lastUnreadList.size(), s);

        s = "";/* w ww. j  av a  2 s  . co m*/
        for (Object unr : unreadMessages)
            s += unr.toString() + ",";

        App.logv("New unread (%d): %s", unreadMessages.length, s);
    }

    if (unreadMessages.length > 0) {
        int unreadCount = 0;
        for (Object unread : unreadMessages) {
            if (!lastUnreadList.contains(unread))
                unreadCount++;
        }

        if (App.getConfig().logToConsole())
            App.logv("%d computed new", unreadCount);

        if (unreadCount > 0) {
            String tickerTitle;
            String tickerText;

            if (unreadMessages.length == 1) {
                tickerTitle = context.getString(R.string.new_message);
                tickerText = context.getString(R.string.notify_message_pending_f, account.getScreenName(),
                        Messages.getSender(context, unreadMessages[0]));
            } else {
                tickerTitle = context.getString(R.string.new_messages);
                tickerText = context.getString(R.string.notify_messages_pending_f, account.getScreenName(),
                        unreadMessages.length, account.getDescription());
            }

            Notification notification = new Notification(R.drawable.xbox_stat_notify_message, tickerText,
                    System.currentTimeMillis());

            Intent intent = new Intent(context, MessageList.class);
            intent.putExtra("account", account);

            PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0);

            notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;

            if (unreadMessages.length > 1)
                notification.number = unreadMessages.length;

            notification.ledOnMS = DEFAULT_LIGHTS_ON_MS;
            notification.ledOffMS = DEFAULT_LIGHTS_OFF_MS;
            notification.ledARGB = DEFAULT_LIGHTS_COLOR;
            notification.sound = account.getRingtoneUri();

            if (account.isVibrationEnabled())
                notification.defaults |= Notification.DEFAULT_VIBRATE;

            notification.setLatestEventInfo(context, tickerTitle, tickerText, contentIntent);

            mgr.notify(notificationId, notification);
        }
    } else // No unread messages
    {
        mgr.cancel(notificationId);
    }
}

From source file:com.bonsai.wallet32.WalletService.java

private void showStatusNotification() {
    CharSequence started_txt = getText(R.string.wallet_service_started);
    CharSequence info_txt = getText(R.string.wallet_service_info);

    Notification note = new Notification(R.drawable.ic_stat_notify, started_txt, System.currentTimeMillis());

    Intent intent = new Intent(this, MainActivity.class);

    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);

    // Set the info for the views that show in the notification panel.
    note.setLatestEventInfo(this, getText(R.string.wallet_service_label), info_txt, contentIntent);

    note.flags |= Notification.FLAG_NO_CLEAR;

    startForeground(NOTIFICATION, note);
}

From source file:com.mobiperf.MeasurementScheduler.java

@SuppressWarnings("unused")
private void updateNotificationBar(String notificationMsg) {
    // The intent to launch when the user clicks the expanded notification
    Intent intent = new Intent(this, SpeedometerApp.class);
    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    // This constructor is deprecated in 3.x. But most phones still run 2.x systems
    Notification notice = new Notification(R.drawable.icon_statusbar, notificationMsg,
            System.currentTimeMillis());

    // This is deprecated in 3.x. But most phones still run 2.x systems
    notice.setLatestEventInfo(this, "Speedometer", notificationMsg, pendIntent);

    notificationManager.notify(NOTIFICATION_ID, notice);
}

From source file:com.ecocitizen.service.SensorMapUploaderService.java

private void updateStatus(Status status) {
    if (this.status == status)
        return;//from w  w w.  ja v a2s.co m
    this.status = status;

    Context context = getApplicationContext();
    CharSequence contentTitle = context.getString(com.ecocitizen.app.R.string.notification_smu_title);
    CharSequence tickerText = context.getString(com.ecocitizen.app.R.string.notification_smu_ticker);

    Notification notification;
    long when = System.currentTimeMillis();
    int icon = 0;
    CharSequence contentText = null;

    switch (status) {
    case LOGINERROR:
        icon = ICON_LOGINERROR;
        contentText = context.getString(com.ecocitizen.app.R.string.notification_smu_loginerror);
        break;
    case STANDBY:
        icon = ICON_STANDBY;
        contentText = context.getString(com.ecocitizen.app.R.string.notification_smu_standby);
        break;
    case UPLOADING:
        icon = ICON_UPLOADING;
        contentText = context.getString(com.ecocitizen.app.R.string.notification_smu_uploading);
        break;
    case BLOCKED:
    default:
        icon = ICON_BLOCKED;
        contentText = context.getString(com.ecocitizen.app.R.string.notification_smu_blocked);
        break;
    }
    notification = new Notification(icon, tickerText, when);
    Intent notificationIntent = new Intent(this, TreeViewActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    mNotificationManager.notify(1, notification);
}

From source file:com.mobiperf.MeasurementScheduler.java

/**
 * Create notification that indicates the service is running.
 *///from   ww  w.  j  a v  a2  s  .co  m
private Notification createServiceRunningNotification() {
    // The intent to launch when the user clicks the expanded notification
    Intent intent = new Intent(this, SpeedometerApp.class);
    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    // This constructor is deprecated in 3.x. But most phones still run 2.x systems
    Notification notice = new Notification(R.drawable.icon_statusbar,
            getString(R.string.notificationSchedulerStarted), System.currentTimeMillis());
    notice.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    // This is deprecated in 3.x. But most phones still run 2.x systems
    notice.setLatestEventInfo(this, getString(R.string.app_name),
            getString(R.string.notificationServiceRunning), pendIntent);
    return notice;
}