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:net.tac42.subtails.util.Util.java

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

    // Use the same text for the ticker and the expanded notification
    String title = song.getTitle();
    String text = song.getArtist();

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

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

    // Set the album art.
    try {//from  w  w w. j  a  va  2 s .c  o  m
        int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight();
        Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size);
        if (bitmap == null) {
            // set default album art
            contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
        } else {
            contentView.setImageViewBitmap(R.id.notification_image, bitmap);
        }
    } catch (Exception x) {
        Log.w(TAG, "Failed to get notification cover art", x);
        contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
    }

    // 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;

    Intent notificationIntent = new Intent(context, DownloadActivity.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
    SubtailsAppWidgetProvider.getInstance().notifyChange(context, downloadService, true);
}

From source file:com.plusot.senselib.SenseMain.java

@SuppressWarnings("deprecation")
public void notifyMe() {
    String version = "";
    try {/*w  w w  .j a  v a  2  s  . com*/
        PackageInfo info = Globals.appContext.getPackageManager()
                .getPackageInfo(Globals.appContext.getPackageName(), 0);
        version = " " + info.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    Notification note = new Notification(SenseGlobals.notifyIcon, Globals.TAG + version,
            System.currentTimeMillis());
    //String[] hints = Globals.appContext.getResources().getStringArray(R.array.hint_items);
    //String hint = hints[(int)(Math.random() * (hints.length - 1))];
    PendingIntent intent = PendingIntent.getActivity(Globals.appContext, 0,
            new Intent(Globals.appContext, SenseGlobals.mainClass), 0);
    note.setLatestEventInfo(Globals.appContext, Globals.TAG + version,
            Globals.appContext.getString(R.string.hello), intent);
    //note.ledOnMS = 1000;
    //note.ledOffMS = 1000;
    //note.ledARGB = 0xFFFFFFFF;
    //note.tickerText = hint;
    //note.number=++noteCount;
    note.flags |= Notification.FLAG_ONGOING_EVENT;
    //note.vibrate=new long[] {20L, 50L}; 

    noteManager.notify(NOTIFY_ME_ID, note);
}

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

private void showStatusNotification() {
    // In this sample, we'll use the same text for the ticker and
    // the expanded notification
    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:org.klnusbaum.udj.network.PlaylistSyncService.java

private void alertException(Account account, Intent originalIntent, int titleRes, int contentRes,
        int notificationId) {

    PendingIntent pe = PendingIntent.getService(this, 0, originalIntent, 0);
    Notification notification = new Notification(R.drawable.udjlauncher, "", System.currentTimeMillis());
    notification.setLatestEventInfo(this, getString(titleRes), getString(contentRes), pe);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(notificationId, notification);
}

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

protected void showNotification(CharSequence from, CharSequence message) {
    // look up the notification manager service
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    // The PendingIntent to launch our activity if the user selects this
    // notification

    //,/* ww  w . ja  v a  2 s  .  c o  m*/
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, IncomingMessageView.class), 0);

    // The ticker text, this uses a formatted string so our message could be
    // localized
    String tickerText = getString(R.string.imcoming_message_ticker_text, message);

    // construct the Notification object.
    Notification notif = new Notification(R.drawable.stat_sample, tickerText, System.currentTimeMillis());

    // Set the info for the views that show in the notification panel.
    notif.setLatestEventInfo(this, from, message, contentIntent);

    //   

    //
    Date dt = new Date();
    if (IsDuringWorkHours(dt)) {
        notif.defaults |= (Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
    } else {
        notif.defaults |= (Notification.DEFAULT_VIBRATE);
    }

    // after a 100ms delay, vibrate for 250ms, pause for 100 ms and
    // then vibrate for 500ms.//
    notif.vibrate = new long[] { 100, 250, 100, 500 };

    nm.notify(R.string.imcoming_message_ticker_text, notif);
}

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);/*from  w w w. j  av a  2 s.c  o  m*/
}

From source file:com.halseyburgund.rwframework.core.RWService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // intent will be null on restart!
    if (intent != null) {
        getSettingsFromIntent(intent);/* w ww  .  j  a  v a  2  s.  co m*/
    }

    // create a pending intent to start the specified activity from the notification
    Intent ovIntent = new Intent(this, mNotificationActivity);
    mNotificationPendingIntent = PendingIntent.getActivity(this, 0, ovIntent, Intent.FLAG_ACTIVITY_NEW_TASK);

    // create a notification and move service to foreground
    mRwNotification = new Notification(mNotificationIconId, "Roundware Service Started",
            System.currentTimeMillis());
    mRwNotification.number = 1;
    mRwNotification.flags = mRwNotification.flags | Notification.FLAG_FOREGROUND_SERVICE
            | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
    setNotificationText("");

    startForeground(NOTIFICATION_ID, mRwNotification);

    // try to go on-line, this will attempt to get the configuration and tags
    manageSessionState(SessionState.ON_LINE);

    return Service.START_STICKY;
}

From source file:net.ben.subsonic.androidapp.util.Util.java

public static void showPlayingNotification(final Context context, Handler handler, MusicDirectory.Entry song) {

    // Use the same text for the ticker and the expanded notification
    String title = song.getTitle();

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

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, FragActivity.class),
            0);/* w w w  . j a  v  a 2 s  .com*/

    String text = song.getArtist();
    notification.setLatestEventInfo(context, title, text, contentIntent);

    // Send the notification.
    handler.post(new Runnable() {
        @Override
        public void run() {
            NotificationManager notificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(Constants.NOTIFICATION_ID_PLAYING, notification);
        }
    });

    // Update widget
    DownloadService service = DownloadServiceImpl.getInstance();
    if (service != null) {
        SubsonicAppWidgetProvider.getInstance().notifyChange(context, service, true);
    }
}

From source file:github.daneren2005.dsub.util.Util.java

public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService,
        Handler handler, MusicDirectory.Entry song) {
    // Set the icon, scrolling text and timestamp
    final Notification notification = new Notification(R.drawable.stat_notify_playing, song.getTitle(),
            System.currentTimeMillis());
    notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    boolean playing = downloadService.getPlayerState() == PlayerState.STARTED;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        RemoteViews expandedContentView = new RemoteViews(context.getPackageName(),
                R.layout.notification_expanded);
        setupViews(expandedContentView, context, song, playing);
        notification.bigContentView = expandedContentView;
    }/*from w ww .  j a va2s. c  om*/

    RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification);
    setupViews(smallContentView, context, song, playing);
    notification.contentView = smallContentView;

    Intent notificationIntent = new Intent(context, DownloadActivity.class);
    notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    handler.post(new Runnable() {
        @Override
        public void run() {
            downloadService.startForeground(Constants.NOTIFICATION_ID_PLAYING, notification);
        }
    });

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

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);
}