Example usage for android.app Notification Notification

List of usage examples for android.app Notification Notification

Introduction

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

Prototype

@Deprecated
public Notification(int icon, CharSequence tickerText, long when) 

Source Link

Document

Constructs a Notification object with the information needed to have a status bar icon without the standard expanded view.

Usage

From source file:com.pendragon.blueconnect.BluetoothChat.java

public void displayNotification() {
    Intent i = new Intent("notify_filter");

    i.putExtra("notificationID", notificationID);
    PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.app_icon, "Notificacion Bluetooth",
            System.currentTimeMillis());
    CharSequence from = "Manager ";
    CharSequence message = "Nuevo mensaje recibido";
    notification.setLatestEventInfo(this, from, message, pi);
    notification.vibrate = new long[] { 100, 250, 100, 500 };
    nm.notify(notificationID, notification);

}

From source file:com.dafeng.upgradeapp.util.AutoUpdateApk.java

protected 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) {
        setChanged();//  ww  w .j av a  2  s .  co m
        notifyObservers(AUTOUPDATE_HAVE_UPDATE);

        // raise notification
        Notification notification = new Notification(appIcon, appName + " update", System.currentTimeMillis());
        notification.flags |= NOTIFICATION_FLAGS;

        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);
        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.ecocitizen.service.SensorMapUploaderService.java

private void updateStatus(Status status) {
    if (this.status == status)
        return;// ww  w. j a  v a  2  s  . 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:uk.ac.horizon.ubihelper.service.LogManager.java

private void signalError(String error) {
    // force re-check...
    currentLogDir = null;//w  w w .  j  a  v a 2 s  .  c o m
    if (errorNotificationVisible && error.equals(errorNotificationText))
        return;
    errorNotificationText = error;

    int icon = R.drawable.log_error_notification_icon;
    CharSequence tickerText = error;
    long when = System.currentTimeMillis();

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

    Context context = service;
    CharSequence contentTitle = "Ubihelper Logging";
    CharSequence contentText = error;
    Intent notificationIntent = new Intent(LoggingPreferences.INTENT);
    PendingIntent contentIntent = PendingIntent.getActivity(service, 0, notificationIntent, 0);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    NotificationManager mNotificationManager = (NotificationManager) service
            .getSystemService(Service.NOTIFICATION_SERVICE);
    //service.(ci.notificationId, notification);   
    mNotificationManager.notify(ERROR_NOTIFICATION_ID, notification);
    errorNotificationVisible = true;
}

From source file:org.kaoriha.phonegap.plugins.releasenotification.Notifier.java

private void pollBackground() {
    if (getToken() == null) {
        rescheduleAfterFail();/*from  w  ww .  j  a v  a2s.co  m*/
        return;
    }

    ToNextReleasePolling tp = new ToNextReleasePolling();
    tp.poll();
    if (tp.isFailed) {
        Log.d(TAG, "ToNextReleasePolling failed");
        rescheduleAfterFail();
        return;
    }

    CataloguePolling cp = new CataloguePolling();
    cp.poll();
    if (cp.isFailed) {
        Log.d(TAG, "CataloguePolling failed");
        rescheduleAfterFail();
        return;
    }
    if (!cp.isNew) {
        if (tp.toNextRelease == -1) {
            schedule(RESCHEDULE_NEXT_UNKNOWN_SPAN);
        } else {
            schedule(tp.toNextRelease);
        }
        Log.d(TAG, "CataloguePolling not new");
        return;
    }

    String pushMessage;
    if (cp.catalogue.has(CATALOGUE_PUSH_MESSAGE_KEY)) {
        try {
            pushMessage = cp.catalogue.getString(CATALOGUE_PUSH_MESSAGE_KEY);
        } catch (JSONException e) {
            Log.i(TAG, "pollBackground()", e);
            pushMessage = pref.getString(SPKEY_DEFAULT_PUSH_MESSAGE, null);
        }
    } else {
        pushMessage = pref.getString(SPKEY_DEFAULT_PUSH_MESSAGE, null);
    }

    String lastSid;
    try {
        lastSid = getLastSid(cp.catalogue);
        if (lastSid.equals(pref.getString(SPKEY_LAST_SID, null))) {
            schedule(tp.toNextRelease);
        }
    } catch (JSONException e) {
        Log.d(TAG, "bad JSON", e);
        rescheduleAfterFail();
        return;
    }

    int icon = R.drawable.notification;
    Notification n = new Notification(icon, pushMessage, System.currentTimeMillis());
    n.flags = Notification.FLAG_AUTO_CANCEL;
    Intent i = new Intent(ctx, FlowerflowerActivity.class);
    i.setAction(Intent.ACTION_MAIN);
    i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pi = PendingIntent.getActivity(ctx, 0, i, 0);
    n.setLatestEventInfo(ctx.getApplicationContext(), pref.getString(SPKEY_TITLE, null), pushMessage, pi);
    NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(NOTIFICATION_ID, n);

    pref.edit().putString(SPKEY_LAST_SID, lastSid).putString(SPKEY_LAST_CATALOGUE_ETAG, cp.etag).commit();

    clearFailRepeat();

    schedule(tp.toNextRelease);

    Log.d(TAG, "pollBackground() success");
}

From source file:com.google.appinventor.components.runtime.ProbeBase.java

@SimpleFunction(description = "Create a notication with message to wake up "
        + "another activity when tap on the notification")
public void CreateNotification(String title, String text, boolean enabledSound, boolean enabledVibrate,
        String packageName, String className, String extraKey, String extraVal) throws ClassNotFoundException {

    Intent activityToLaunch = new Intent(Intent.ACTION_MAIN);

    Log.i(TAG, "packageName: " + packageName);
    Log.i(TAG, "className: " + className);

    // for local AI instance, all classes are under the package
    // "appinventor.ai_test"
    // but for those runs on Google AppSpot(AppEngine), the package name will be
    // "appinventor.ai_GoogleAccountUserName"
    // e.g. pakageName = appinventor.ai_HomerSimpson.HelloPurr
    // && className = appinventor.ai_HomerSimpson.HelloPurr.Screen1

    ComponentName component = new ComponentName(packageName, className);
    activityToLaunch.setComponent(component);
    activityToLaunch.putExtra(extraKey, extraVal);

    Log.i(TAG, "we found the class for intent to send into notificaiton");

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

    mContentIntent = PendingIntent.getActivity(mainUIThreadActivity, 0, activityToLaunch, 0);

    Long currentTimeMillis = System.currentTimeMillis();
    notification = new Notification(R.drawable.stat_notify_chat, "Activate Notification!", currentTimeMillis);

    Log.i(TAG, "After creating notification");
    notification.contentIntent = mContentIntent;
    notification.flags = Notification.FLAG_AUTO_CANCEL;

    // reset the notification
    notification.defaults = 0;//from  w w w .  ja v a  2 s .co  m

    if (enabledSound)
        notification.defaults |= Notification.DEFAULT_SOUND;

    if (enabledVibrate)
        notification.defaults |= Notification.DEFAULT_VIBRATE;

    notification.setLatestEventInfo(mainUIThreadActivity, (CharSequence) title, (CharSequence) text,
            mContentIntent);
    Log.i(TAG, "after updated notification contents");
    mNM.notify(PROBE_NOTIFICATION_ID, notification);
    Log.i(TAG, "notified");

}

From source file:com.autoupdateapk.AutoUpdateApk.java

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

    // nm.cancel( NOTIFICATION_ID ); // tried this, but it just doesn't do
    // the trick =(
    nm.cancelAll();//from w ww.  j  a  va 2s .co m

    String update_file = preferences.getString(UPDATE_FILE, "");
    if (update_file.length() > 0) {
        setChanged();
        notifyObservers(AUTOUPDATE_HAVE_UPDATE);

        // raise notification
        Notification notification = new Notification(appIcon, appName + " update", System.currentTimeMillis());
        notification.flags |= NOTIFICATION_FLAGS;

        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);
        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:org.mozilla.gecko.updater.UpdateService.java

private void showDownloadFailure() {
    Notification notification = new Notification(R.drawable.ic_status_logo, null, System.currentTimeMillis());

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

    PendingIntent contentIntent = PendingIntent.getService(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    notification.setLatestEventInfo(this, getResources().getString(R.string.updater_downloading_title_failed),
            getResources().getString(R.string.updater_downloading_retry), contentIntent);

    mNotificationManager.notify(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 www.ja  v  a  2  s  .  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:com.dmbstream.android.util.Util.java

public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService,
        Handler handler, Track song) {

    // Use the same text for the ticker and the expanded notification
    String title = song.title;/*from   ww  w  .  j  a  v a  2 s.  co m*/
    String text = song.artist;

    // Set the icon, scrolling text and timestamp
    final Notification notification = new Notification(R.drawable.notify_playing, title,
            System.currentTimeMillis());
    notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.partial_notification);

    // set the text for the notifications
    contentView.setTextViewText(R.id.notification_title, title);
    contentView.setTextViewText(R.id.notification_artist, text);

    Pair<Integer, Integer> colors = getNotificationTextColors(context);
    if (colors.getFirst() != null) {
        contentView.setTextColor(R.id.notification_title, colors.getFirst());
    }
    if (colors.getSecond() != null) {
        contentView.setTextColor(R.id.notification_artist, colors.getSecond());
    }

    notification.contentView = contentView;

    // Send them to the main menu when if they click the notification
    // TODO: Send them to the concert, playlist, compilation details or chat page?
    Intent notificationIntent = new Intent(context, MainMenuActivity.class);
    notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    // Send the notification and put the service in the foreground.
    handler.post(new Runnable() {
        @Override
        public void run() {
            startForeground(downloadService, Constants.NOTIFICATION_ID_PLAYING, notification);
        }
    });

    // Update widget
    DmbstreamAppWidgetProvider.getInstance().notifyChange(context, downloadService, true);
}