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.android.mms.transaction.MessagingNotification.java

/**
 * This method sends a notification to NotificationManager to display
 * an dialog indicating the message memory is full.
 *///ww  w  .jav a 2 s .co m
private static void sendFullNotification(Context context) {
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    String title = context.getString(R.string.sms_full_title);
    String description = context.getString(R.string.sms_full_body);
    PendingIntent intent = PendingIntent.getActivity(context, 0, new Intent(), 0);
    Notification notification = new Notification();
    notification.icon = R.drawable.stat_notify_sms_failed;
    notification.tickerText = title;
    notification.setLatestEventInfo(context, title, description, intent);
    nm.notify(FULL_NOTIFICATION_ID, notification);
}

From source file:com.olearyp.gusto.Expsetup.java

protected void sendCommand(final String command, final String description, final String state) {
    final Intent runCmd = new Intent("com.olearyp.gusto.SUEXEC");
    runCmd.setData(/*from   w  ww .j a v a 2s . c  om*/
            Uri.fromParts("command", ". /system/bin/exp_script.sh.lib && read_in_ep_config && " + command, ""))
            .putExtra("com.olearyp.gusto.STATE", state);
    final Notification note = new Notification(R.drawable.icon,
            description.substring(0, 1).toUpperCase() + description.substring(1) + "...",
            System.currentTimeMillis());
    note.setLatestEventInfo(Expsetup.this, getString(R.string.app_name),
            getString(R.string.app_name) + " is " + description + "...",
            PendingIntent.getBroadcast(Expsetup.this, 0, null, 0));
    runCmd.putExtra("com.olearyp.gusto.RUN_NOTIFICATION", note);
    startService(runCmd);
    setServerState(state);
    if (getServerState().equals(getString(R.string.reboot_manual_flash_required))) {
        final Intent intent = new Intent("com.olearyp.gusto.SUEXEC")
                .setData(Uri.fromParts("commandid", Integer.toString(R.string.reboot_recovery), ""));
        final PendingIntent contentIntent = PendingIntent.getService(this, 0, intent, 0);
        final Notification rebootNote = new Notification(R.drawable.status_reboot,
                getString(R.string.reboot_recovery_required_msg), System.currentTimeMillis());
        rebootNote.setLatestEventInfo(this, "GUSTO reboot request",
                getString(R.string.reboot_recovery_doit_msg), contentIntent);
        rebootNote.deleteIntent = PendingIntent.getBroadcast(this, 0,
                new Intent("com.olearyp.gusto.RESET_SERVER_STATE"), 0);
        rebootNote.flags |= Notification.FLAG_SHOW_LIGHTS;
        rebootNote.ledOnMS = 200;
        rebootNote.ledOffMS = 400;
        rebootNote.ledARGB = Color.argb(255, 255, 0, 0);
        nm.notify(REBOOT_NOTIFICATION, rebootNote);
    } else if (getServerState().equals(getString(R.string.reboot_recovery_required))) {
        final Intent intent = new Intent("com.olearyp.gusto.SUEXEC")
                .setData(Uri.fromParts("commandid", Integer.toString(R.string.reboot), ""));
        final PendingIntent contentIntent = PendingIntent.getService(this, 0, intent, 0);
        final Notification rebootNote = new Notification(R.drawable.status_reboot,
                getString(R.string.reboot_autoflash_required_msg), System.currentTimeMillis());
        rebootNote.setLatestEventInfo(this, "GUSTO reboot request",
                getString(R.string.reboot_autoflash_doit_msg), contentIntent);
        rebootNote.deleteIntent = PendingIntent.getBroadcast(this, 0,
                new Intent("com.olearyp.gusto.RESET_SERVER_STATE"), 0);
        rebootNote.flags |= Notification.FLAG_SHOW_LIGHTS;
        rebootNote.ledOnMS = 200;
        rebootNote.ledOffMS = 600;
        rebootNote.ledARGB = Color.argb(255, 255, 255, 0);
        nm.notify(REBOOT_NOTIFICATION, rebootNote);
    } else if (getServerState().equals(getString(R.string.reboot_required))) {
        final Intent intent = new Intent("com.olearyp.gusto.SUEXEC")
                .setData(Uri.fromParts("commandid", Integer.toString(R.string.reboot), ""));
        final PendingIntent contentIntent = PendingIntent.getService(this, 0, intent, 0);
        final Notification rebootNote = new Notification(R.drawable.status_reboot,
                getString(R.string.reboot_required_msg), System.currentTimeMillis());
        rebootNote.setLatestEventInfo(this, "GUSTO reboot request", getString(R.string.reboot_doit_msg),
                contentIntent);
        rebootNote.deleteIntent = PendingIntent.getBroadcast(this, 0,
                new Intent("com.olearyp.gusto.RESET_SERVER_STATE"), 0);
        rebootNote.flags |= Notification.FLAG_SHOW_LIGHTS;
        rebootNote.ledOnMS = 200;
        rebootNote.ledOffMS = 600;
        rebootNote.ledARGB = Color.argb(255, 255, 255, 0);
        nm.notify(REBOOT_NOTIFICATION, rebootNote);
    }
}

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

private void showProximityNotification(String string) {
    final NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification note = new Notification(R.drawable.status, "Friend@ notification!",
            System.currentTimeMillis());
    Intent i = new Intent(this, AlertList.class);

    //      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, "Friend@ notification", string, pi);

    mgr.notify(NOTIFICATION_ID, note);//from w  w  w  .  ja  v a2  s . c o  m

}

From source file:uk.ac.horizon.ubihelper.service.Service.java

@Override
public void onCreate() {
    // One-time set-up...
    Log.d(TAG, "onCreate()");
    // TODO/*from w w w .  j a v a  2s.co  m*/
    super.onCreate();
    // handler for requests
    mHandler = new Handler();
    // create taskbar notification
    int icon = R.drawable.service_notification_icon;
    CharSequence tickerText = getText(R.string.notification_start_message);
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);

    Context context = this;
    CharSequence contentTitle = getText(R.string.notification_title);
    CharSequence contentText = getText(R.string.notification_description);
    Intent notificationIntent = new Intent(this, MainPreferences.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

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

    startForeground(RUNNING_ID, notification);

    channelManager = new ChannelManager(peerChannelFactory);
    // sensors
    if (!isEmulator()) {
        Log.d(TAG, "Create sensor channels...");

        SensorChannel magnetic = new SensorChannel("magnetic", this, Sensor.TYPE_MAGNETIC_FIELD);
        channelManager.addChannel(magnetic);
        SensorChannel accelerometer = new SensorChannel("accelerometer", this, Sensor.TYPE_ACCELEROMETER);
        channelManager.addChannel(accelerometer);
        SensorChannel gyro = new SensorChannel("gyro", this, Sensor.TYPE_GYROSCOPE);
        channelManager.addChannel(gyro);
        SensorChannel light = new SensorChannel("light", this, Sensor.TYPE_LIGHT);
        channelManager.addChannel(light);
        SensorChannel pressure = new SensorChannel("pressure", this, Sensor.TYPE_PRESSURE);
        channelManager.addChannel(pressure);
        SensorChannel proximity = new SensorChannel("proximity", this, Sensor.TYPE_PROXIMITY);
        channelManager.addChannel(proximity);
        SensorChannel temperature = new SensorChannel("temperature", this, Sensor.TYPE_TEMPERATURE);
        channelManager.addChannel(temperature);

        try {
            Field f = Sensor.class.getField("TYPE_AMBIENT_TEMPERATURE");
            SensorChannel sc = new SensorChannel("ambientTemperature", this, f.getInt(null));
            channelManager.addChannel(sc);
        } catch (Exception e) {
            Log.d(TAG, "Could not get field Sensor.TYPE_AMBIENT_TEMPERATURE");
        }
        try {
            Field f = Sensor.class.getField("TYPE_RELATIVE_HUMIDITY");
            SensorChannel sc = new SensorChannel("relativeHumidity", this, f.getInt(null));
            channelManager.addChannel(sc);
        } catch (Exception e) {
            Log.d(TAG, "Could not get field Sensor.TYPE_AMBIENT_TEMPERATURE");
        }

        // all sensors by full name
        SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        if (sensorManager != null) {
            List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
            for (Sensor sensor : sensors) {
                SensorChannel sc = new SensorChannel("sensor." + sensor.getName(), this, sensor);
                channelManager.addChannel(sc);
            }
        }
        BluetoothDiscoveryChannel btchannel = new BluetoothDiscoveryChannel(this, mHandler, "bluetooth");
        channelManager.addChannel(btchannel);
        WifiScannerChannel wifichannel = new WifiScannerChannel(this, mHandler, "wifi");
        channelManager.addChannel(wifichannel);
        GpsStatusChannel gpsstatus = new GpsStatusChannel("gpsstatus", this);
        channelManager.addChannel(gpsstatus);
        CellLocationChannel cellchannel = new CellLocationChannel(mHandler, this, "cell.location", false);
        channelManager.addChannel(cellchannel);
        CellLocationChannel cellchannel2 = new CellLocationChannel(mHandler, this, "cell.neighbors", true);
        channelManager.addChannel(cellchannel2);
        CellStrengthChannel cellchannel3 = new CellStrengthChannel(this, "cell.strength");
        channelManager.addChannel(cellchannel3);
    }
    channelManager.addChannel(new TimeChannel(mHandler, "time"));
    List<String> locationProviders = LocationChannel.getAllProviders(this);
    for (String provider : locationProviders) {
        LocationChannel locchannel = new LocationChannel("location." + provider, this, provider);
        channelManager.addChannel(locchannel);
    }

    channelManager.addChannel(new MicChannel(mHandler, "mic"));

    Log.d(TAG, "Create http server...");

    // http server
    httpPort = getPort();

    httpListener = new HttpListener(this, httpPort);
    httpListener.start();

    // peer communication
    peerManager = new PeerManager(this);
    int serverPort = peerManager.getServerPort();

    channelManager.addChannel(new EnabledPeersChannel(this, peerManager, "peers"));

    // wifi discovery
    wifiDiscoveryManager = new WifiDiscoveryManager(this);
    wifiDiscoverable = getWifiDiscoverable();
    wifiDiscoveryManager.setServerPort(serverPort);
    wifiDiscoveryManager.setEnabled(wifiDiscoverable);

    bluetooth = BluetoothAdapter.getDefaultAdapter();
    if (bluetooth != null)
        btmac = bluetooth.getAddress();

    telephony = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    if (telephony != null)
        imei = telephony.getDeviceId();

    logManager = new LogManager(this, channelManager);
    logManager.checkPreferences();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.registerOnSharedPreferenceChangeListener(onRunChangeListener);

    Log.d(TAG, "onCreate() finished");
}

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

private void checkMythDroid() {

    if (MDVer == null)
        return;// w  ww  .j  a  va 2 s . c  o  m

    Version runningVer;
    try {
        runningVer = new Version(getPackageManager().getPackageInfo(getPackageName(), 0).versionName, null);
    } catch (NameNotFoundException e) {
        return;
    }

    if (runningVer.compareTo(MDVer) >= 0) {
        LogUtil.debug("Already running latest version of MythDroid"); //$NON-NLS-1$
        return;
    }

    LogUtil.debug("Version " + MDVer.toString() + //$NON-NLS-1$
            " is available (current version is " + runningVer.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") + "MythDroid" + //$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(MDACTION);
    intent.putExtra(VER, MDVer.toString());
    intent.putExtra(URL, MDVer.url.toString());

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

    nm.notify(CHECKMD, notification);

}

From source file:com.wso2.mobile.mdm.services.Operation.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from ww  w  . j a v a  2 s  .  c o 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, NotifyActivity.class);
    notificationIntent.putExtra("notification", 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, 0);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notificationManager.notify(0, notification);
    Toast.makeText(context, message, Toast.LENGTH_LONG).show();
}

From source file:de.wikilab.android.friendica01.FileUploadService.java

private void showFailMsg(Context ctx, String txt) {
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    Log.e("Andfrnd/UploadFile", "Upload FAILED: " + txt);

    //Instantiate the Notification:
    CharSequence tickerText = "Upload failed, please retry!";
    Notification notification = new Notification(R.drawable.arrow_up, tickerText, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    //Define the Notification's expanded message and Intent:
    Context context = getApplicationContext();
    CharSequence contentTitle = "Upload failed, click to retry!";
    CharSequence contentText = txt;
    Intent notificationIntent = new Intent(this, FriendicaImgUploadActivity.class);
    Bundle b = new Bundle();
    b.putParcelable(Intent.EXTRA_STREAM, fileToUpload);
    b.putString(Intent.EXTRA_SUBJECT, subject);
    b.putString(EXTRA_DESCTEXT, descText);

    notificationIntent.putExtras(b);/*  w  w  w  . j  a v a2 s . co m*/
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    //Pass the Notification to the NotificationManager:
    mNotificationManager.notify(UPLOAD_FAILED_ID, notification);
    //Toast.makeText(ctx, "Upload failed, please retry:\n" + txt, Toast.LENGTH_LONG).show();
}

From source file:com.cloverstudio.spika.GCMIntentService.java

@SuppressWarnings("deprecation")
public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras) {

    if (fromName != null) {
        final NotificationManager notificationManager = (NotificationManager) getSystemService(
                NOTIFICATION_SERVICE);/*from   w w w  . j  a  va2s. c  om*/
        Notification notification = new Notification(R.drawable.icon_notification, message,
                System.currentTimeMillis());
        notification.number = mNotificationCounter + 1;
        mNotificationCounter = mNotificationCounter + 1;

        Intent intent = new Intent(this, SplashScreenActivity.class);
        intent.replaceExtras(pushExtras);
        intent.putExtra(Const.PUSH_INTENT, true);
        intent.setAction(Long.toString(System.currentTimeMillis()));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND
                | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, notification.number, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        notification.setLatestEventInfo(this, context.getString(R.string.app_name), message, pendingIntent);
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        String notificationId = Double.toString(Math.random());
        notificationManager.notify(notificationId, 0, notification);
    }
}

From source file:com.siahmsoft.soundroid.sdk7.services.UploadService.java

/**
 * Show a notification while this service is running.
 *//* w  w w.  j  a v a  2  s . c  o m*/
private void showNotification(String text) {
    // Set the icon, scrolling text and timestamp
    Notification notification = new Notification(R.drawable.uploadtocloud, text, System.currentTimeMillis());

    // The PendingIntent to launch our activity if the user selects this notification
    Intent i = new Intent(this, MeActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    /*Bundle bundle = new Bundle();
    bundle.putInt("idTrack", soundcloudTrack.getmIdTrack());
    i.putExtras(bundle);*/

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

    // Set the info for the views that show in the notification panel.
    notification.setLatestEventInfo(this, "Uploading...", text, contentIntent);

    // We show this for as long as our service is processing a command.
    notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL;
    notification.number = totalUploads;

    // Send the notification.
    // We use a string id because it is a unique number.  We use it later to cancel.
    mNM.notify(777, notification);
}

From source file:de.mangelow.throughput.NotificationService.java

@SuppressWarnings("deprecation")
private void modifyNotification(int drawable, String ticker, String title, String subtitle, Intent i) {

    boolean showticker = MainActivity.loadBooleanPref(context, MainActivity.SHOWTICKER,
            MainActivity.SHOWTICKER_DEFAULT);
    if (!showticker)
        ticker = null;//  w w  w . j  av  a  2s  .  c o  m

    NotificationManager nmanager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    PendingIntent pi = PendingIntent.getActivity(this, 0, i, NOTIFICATION_ID);
    Notification n = null;

    if (Build.VERSION.SDK_INT < 11) {

        n = new Notification(drawable, ticker, System.currentTimeMillis());
        n.flags |= Notification.FLAG_NO_CLEAR;
        n.setLatestEventInfo(this, title, subtitle, pi);

    } else {

        if (nb == null) {
            nb = new Notification.Builder(context);
            nb.setPriority(Notification.PRIORITY_LOW);
            nb.setAutoCancel(true);
        }

        nb.setSmallIcon(drawable);
        if (ticker != null)
            nb.setTicker(ticker);
        nb.setContentTitle(title);
        nb.setContentText(subtitle);
        nb.setContentIntent(pi);

        n = nb.build();
        n.flags = Notification.FLAG_NO_CLEAR;

    }

    nmanager.notify(NOTIFICATION_ID, n);

    //

    if (mResultReceiver != null) {

        Bundle bundle = new Bundle();
        bundle.putInt("drawable", drawable);
        bundle.putString("title", title);
        bundle.putString("subtitle", subtitle);
        mResultReceiver.send(0, bundle);

    }

}