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:com.pandoroid.PandoraRadioService.java

public void setNotification() {
    if (!m_paused) {
        try {//from w w w .  j  av a 2s .  co  m
            Song tmp_song;
            tmp_song = m_song_playback.getSong();
            Notification notification = new Notification(R.drawable.icon, "Pandoroid Radio",
                    System.currentTimeMillis());
            Intent notificationIntent = new Intent(this, PandoroidPlayer.class);
            PendingIntent contentIntent = PendingIntent.getActivity(this, NOTIFICATION_SONG_PLAYING,
                    notificationIntent, 0);
            notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE;
            notification.setLatestEventInfo(getApplicationContext(), tmp_song.getTitle(),
                    tmp_song.getArtist() + " on " + tmp_song.getAlbum(), contentIntent);
            startForeground(NOTIFICATION_SONG_PLAYING, notification);
        } catch (Exception e) {
        }
    }
}

From source file:org.mythdroid.util.UpdateService.java

private void checkMDD(String addr) {

    if (MDDVer == null)
        return;/*from   www . ja  va  2s .c  o m*/

    Version currentVer;
    try {
        currentVer = new Version(MDDManager.getVersion(addr), null);
    } catch (NumberFormatException e) {
        ErrUtil.logErr(e);
        return;
    } catch (IOException e) {
        ErrUtil.logErr(e);
        return;
    }

    if (currentVer.compareTo(MDDVer) >= 0) {
        LogUtil.debug("MDD on " + addr + " is already the latest version" //$NON-NLS-1$ //$NON-NLS-2$
        );
        return;
    }

    LogUtil.debug("MDD ver " + MDDVer.toString() + " is available (current ver on " + //$NON-NLS-1$ //$NON-NLS-2$
            addr + " is " + currentVer.toString() + ")" //$NON-NLS-1$ //$NON-NLS-2$
    );

    if (MDVer != null && MDVer.compareTo(MDDVer) != 0) {
        LogUtil.warn("Version mismatch:" + " MythDroid is " + MDVer.toString() + //$NON-NLS-1$ //$NON-NLS-2$
                ", MDD on " + addr + " is " + MDDVer.toString() //$NON-NLS-1$ //$NON-NLS-2$ 
        );
    }

    final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    final Notification notification = new Notification(R.drawable.logo,
            Messages.getString("UpdateService.0") + "MDD" + //$NON-NLS-1$ //$NON-NLS-2$
                    Messages.getString("UpdateService.1"), //$NON-NLS-1$
            System.currentTimeMillis());

    notification.flags = Notification.FLAG_AUTO_CANCEL;

    final Intent intent = new Intent(MDDACTION);
    intent.putExtra(ADDR, addr);
    intent.putExtra(VER, MDDVer.toString());
    intent.putExtra(URL, MDDVer.url.toString());

    notification.setLatestEventInfo(getApplicationContext(), "MDD" + Messages.getString("UpdateService.2"), //$NON-NLS-1$ //$NON-NLS-2$
            MDDVer.toString() + Messages.getString("UpdateService.1") + //$NON-NLS-1$ 
                    Messages.getString("UpdateService.3"), //$NON-NLS-1$
            PendingIntent.getBroadcast(this, 0, intent, 0));

    nm.notify(CHECKMDD, notification);

}

From source file:nl.sogeti.android.gpstracker.actions.NameTrack.java

private void startDelayNotification() {
    int resId = R.string.dialog_routename_title;
    int icon = R.drawable.ic_maps_indicator_current_position;
    CharSequence tickerText = getResources().getString(resId);
    long when = System.currentTimeMillis();

    Notification nameNotification = new Notification(icon, tickerText, when);
    nameNotification.flags |= Notification.FLAG_AUTO_CANCEL;

    CharSequence contentTitle = getResources().getString(R.string.app_name);
    CharSequence contentText = getResources().getString(resId);

    Intent notificationIntent = new Intent(this, NameTrack.class);
    notificationIntent.setData(mTrackUri);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            Intent.FLAG_ACTIVITY_NEW_TASK);
    nameNotification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);

    NotificationManager noticationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    noticationManager.notify(R.layout.namedialog, nameNotification);
}

From source file:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java

private void oldPushNotification(Context context, Intent intent) {
    PushReportUtility.log("oldPushNotification->isForground = " + EBrowserActivity.isForground);
    if (EBrowserActivity.isForground) {
        if (mContext != null) {
            intent.putExtra("ntype", F_TYPE_PUSH);
            ((EBrowserActivity) mContext).handleIntent(intent);
        }/*from   w w  w.  j ava  2 s. c o m*/
    } else {
        CharSequence tickerText = intent.getStringExtra("title"); // ????
        Resources res = context.getResources();
        int icon = res.getIdentifier("icon", "drawable", intent.getPackage());
        long when = System.currentTimeMillis(); // ?
        // ??Nofification

        String notifyTitle = null;
        String pushMessage = intent.getStringExtra("message");
        String value = intent.getStringExtra("data"); // ??json
        try {
            JSONObject bodyJson = new JSONObject(value);
            notifyTitle = bodyJson.getString("msgName");// ?
        } catch (Exception e) {
            PushReportUtility.oe("onReceive", e);
        }
        if (TextUtils.isEmpty(notifyTitle)) {
            notifyTitle = intent.getStringExtra("widgetName");// msgNamewidgetName?
        }
        if (TextUtils.isEmpty(notifyTitle)) {
            notifyTitle = "APPCAN";// widgetNameAPPCAN?
        }
        CharSequence contentTitle = notifyTitle; // ?
        Intent notificationIntent = new Intent(context, EBrowserActivity.class); // ??Activity
        notificationIntent.putExtra("data", value);
        notificationIntent.putExtra("message", pushMessage);
        notificationIntent.putExtra("ntype", F_TYPE_PUSH);
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
        Notification notification = new Notification(icon, tickerText, when);
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_SOUND;
        if (Build.VERSION.SDK_INT >= 16) {
            try {
                Field priorityField = Notification.class.getField("priority");
                priorityField.setAccessible(true);
                priorityField.set(notification, 1);
            } catch (Exception e) {
                PushReportUtility.oe("onReceive", e);
            }
        }
        PendingIntent contentIntent = PendingIntent.getActivity(context, notificationNB, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        notification.setLatestEventInfo(context, contentTitle, tickerText, contentIntent);
        // NotificationNotificationManager
        mNotificationManager.notify(notificationNB, notification);
        notificationNB++;
    }
}

From source file:com.beem.project.beem.service.XmppConnectionAdapter.java

/**
 * Update the notification for the Beem status.
 * @param status the status to display.//from w w  w.  j  av a  2s.  c o  m
 * @param text the text to display.
 */
private void updateNotification(int status, String text) {
    Notification mStatusNotification;
    mStatusNotification = new Notification(Status.getIconBarFromStatus(status), text,
            System.currentTimeMillis());
    mStatusNotification.defaults = Notification.DEFAULT_LIGHTS;
    mStatusNotification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    mStatusNotification.setLatestEventInfo(mService, "Beem Status", text,
            PendingIntent.getActivity(mService, 0, new Intent(mService, ChangeStatus.class), 0));
    // bypass the preferences for notification
    mService.getNotificationManager().notify(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
}

From source file:dk.microting.softkeyboard.autoupdateapk.AutoUpdateApk.java

private void raise_notification() {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) context.getSystemService(ns);

    String update_file = preferences.getString(UPDATE_FILE, "");
    if (update_file.length() > 0) {
        // raise notification
        Notification notification = new Notification(appIcon, appName + " update", System.currentTimeMillis());
        notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_NO_CLEAR;

        CharSequence contentTitle = appName + " update available";
        CharSequence contentText = "Select to install";
        Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setDataAndType(
                Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file),
                ANDROID_PACKAGE);/*from  w w w .  j  av  a2  s . com*/
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        nm.notify(NOTIFICATION_ID, notification);
    } else {
        nm.cancel(NOTIFICATION_ID);
    }
}

From source file:com.attentec.AttentecService.java

/**
 * shows a notification in the status bar.
 *///  w  w  w .j  av  a 2 s  .c o m
private void showNotification() {
    //text for display in status bar
    CharSequence text;
    if (PreferencesHelper.getLocationUpdateEnabled(ctx)) {
        text = getText(R.string.service_started);
    } else {
        text = getText(R.string.service_started_no_position);
    }

    //get icon for display status bar
    Notification notification = new Notification(R.drawable.statusbar_icon, text, System.currentTimeMillis());

    //Intent to launch on click in notification list
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Attentec.class), 0);

    //set notification settings
    notification.setLatestEventInfo(this, getText(R.string.service_label), text, contentIntent);

    //Send notification
    if (PreferencesHelper.getLocationUpdateEnabled(ctx)) {
        //Log.d(TAG, "Showing notifications: with locations");
        mNM.notify(R.string.service_started, notification);
    } else {
        //Log.d(TAG, "Showing notifications: no locations");
        mNM.notify(R.string.service_started_no_position, notification);
    }
}

From source file:edu.sage.spark.service.XmppConnectionAdapter.java

/**
 * Update the notification for the Beem status.
 * @param status the status to display.//from w w w  . java2s.  c o  m
 * @param text the text to display.
 */
@SuppressWarnings("deprecation")
private void updateNotification(int status, String text) {
    String mNotificationText = "Spark Status"; //almyz125 added this

    Notification mStatusNotification;
    mStatusNotification = new Notification(Status.getIconBarFromStatus(status), text,
            System.currentTimeMillis());
    mStatusNotification.defaults = Notification.DEFAULT_LIGHTS;
    mStatusNotification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    mStatusNotification.setLatestEventInfo(mService, mNotificationText, text, //almyz125 added mNotificationText variable
            PendingIntent.getActivity(mService, 0, new Intent(mService, ChangeStatus.class), 0));
    // bypass the preferences for notification
    mService.getNotificationManager().notify(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
}

From source file:gpsalarm.app.service.PostMonitor.java

private void showNotification(String str, String gid) {
    final NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification note = new Notification(R.drawable.status, "Locate@ Tweet", System.currentTimeMillis());
    Intent i = new Intent(this, AlarmEdit3.class);
    i.putExtra("user", prefs.getString("user", null));
    i.putExtra(ReminderHelper.GLOBAL_ID, gid);
    //      i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|
    //                      Intent.FLAG_ACTIVITY_SINGLE_TOP);
    i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);

    note.setLatestEventInfo(this, "Locate@ Tweet", str, pi);

    mgr.notify(NOTIFICATION_ID, note);// w w  w  .  j a  v  a  2 s  .c om
}

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 ww  w  .  j a  v a2 s  .  co m
            }
        }
    }
}