Example usage for android.app Notification FLAG_ONGOING_EVENT

List of usage examples for android.app Notification FLAG_ONGOING_EVENT

Introduction

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

Prototype

int FLAG_ONGOING_EVENT

To view the source code for android.app Notification FLAG_ONGOING_EVENT.

Click Source Link

Document

Bit to be bitwise-ored into the #flags field that should be set if this notification is in reference to something that is ongoing, like a phone call.

Usage

From source file:github.madmarty.madsonic.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, 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  w  w  .j a  va 2s  .  co  m*/

    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
    MadsonicWidgetProvider.notifyInstances(context, downloadService, true);
}

From source file:com.aniruddhc.acemusic.player.Services.AudioPlaybackService.java

/**
 * Builds and returns a fully constructed Notification for devices 
 * on Jelly Bean and above (API 16+).//from  ww w .  java  2  s .co m
 */
@SuppressLint("NewApi")
private Notification buildJBNotification(SongHelper songHelper) {
    mNotificationBuilder = new NotificationCompat.Builder(mContext);
    mNotificationBuilder.setOngoing(true);
    mNotificationBuilder.setAutoCancel(false);
    mNotificationBuilder.setSmallIcon(R.drawable.notif_icon);

    //Open up the player screen when the user taps on the notification.
    Intent launchNowPlayingIntent = new Intent();
    launchNowPlayingIntent.setAction(AudioPlaybackService.LAUNCH_NOW_PLAYING_ACTION);
    PendingIntent launchNowPlayingPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(),
            0, launchNowPlayingIntent, 0);
    mNotificationBuilder.setContentIntent(launchNowPlayingPendingIntent);

    //Grab the notification layouts.
    RemoteViews notificationView = new RemoteViews(mContext.getPackageName(),
            R.layout.notification_custom_layout);
    RemoteViews expNotificationView = new RemoteViews(mContext.getPackageName(),
            R.layout.notification_custom_expanded_layout);

    //Initialize the notification layout buttons.
    Intent previousTrackIntent = new Intent();
    previousTrackIntent.setAction(AudioPlaybackService.PREVIOUS_ACTION);
    PendingIntent previousTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            previousTrackIntent, 0);

    Intent playPauseTrackIntent = new Intent();
    playPauseTrackIntent.setAction(AudioPlaybackService.PLAY_PAUSE_ACTION);
    PendingIntent playPauseTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            playPauseTrackIntent, 0);

    Intent nextTrackIntent = new Intent();
    nextTrackIntent.setAction(AudioPlaybackService.NEXT_ACTION);
    PendingIntent nextTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            nextTrackIntent, 0);

    Intent stopServiceIntent = new Intent();
    stopServiceIntent.setAction(AudioPlaybackService.STOP_SERVICE);
    PendingIntent stopServicePendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            stopServiceIntent, 0);

    //Check if audio is playing and set the appropriate play/pause button.
    if (mApp.getService().isPlayingMusic()) {
        notificationView.setImageViewResource(R.id.notification_base_play, R.drawable.btn_playback_pause_light);
        expNotificationView.setImageViewResource(R.id.notification_expanded_base_play,
                R.drawable.btn_playback_pause_light);
    } else {
        notificationView.setImageViewResource(R.id.notification_base_play, R.drawable.btn_playback_play_light);
        expNotificationView.setImageViewResource(R.id.notification_expanded_base_play,
                R.drawable.btn_playback_play_light);
    }

    //Set the notification content.
    expNotificationView.setTextViewText(R.id.notification_expanded_base_line_one, songHelper.getTitle());
    expNotificationView.setTextViewText(R.id.notification_expanded_base_line_two, songHelper.getArtist());
    expNotificationView.setTextViewText(R.id.notification_expanded_base_line_three, songHelper.getAlbum());

    notificationView.setTextViewText(R.id.notification_base_line_one, songHelper.getTitle());
    notificationView.setTextViewText(R.id.notification_base_line_two, songHelper.getArtist());

    //Set the states of the next/previous buttons and their pending intents.
    if (mApp.getService().isOnlySongInQueue()) {
        //This is the only song in the queue, so disable the previous/next buttons.
        expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.INVISIBLE);
        expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.INVISIBLE);
        expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play,
                playPauseTrackPendingIntent);

        notificationView.setViewVisibility(R.id.notification_base_next, View.INVISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_previous, View.INVISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);

    } else if (mApp.getService().isFirstSongInQueue()) {
        //This is the the first song in the queue, so disable the previous button.
        expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.INVISIBLE);
        expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.VISIBLE);
        expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play,
                playPauseTrackPendingIntent);
        expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_next,
                nextTrackPendingIntent);

        notificationView.setViewVisibility(R.id.notification_base_previous, View.INVISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_next, View.VISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent);

    } else if (mApp.getService().isLastSongInQueue()) {
        //This is the last song in the cursor, so disable the next button.
        expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.VISIBLE);
        expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.INVISIBLE);
        expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play,
                playPauseTrackPendingIntent);
        expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_next,
                nextTrackPendingIntent);

        notificationView.setViewVisibility(R.id.notification_base_previous, View.VISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_next, View.INVISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent);

    } else {
        //We're smack dab in the middle of the queue, so keep the previous and next buttons enabled.
        expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.VISIBLE);
        expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.VISIBLE);
        expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play,
                playPauseTrackPendingIntent);
        expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_next,
                nextTrackPendingIntent);
        expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_previous,
                previousTrackPendingIntent);

        notificationView.setViewVisibility(R.id.notification_base_previous, View.VISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_next, View.VISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_previous, previousTrackPendingIntent);

    }

    //Set the "Stop Service" pending intents.
    expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_collapse,
            stopServicePendingIntent);
    notificationView.setOnClickPendingIntent(R.id.notification_base_collapse, stopServicePendingIntent);

    //Set the album art.
    expNotificationView.setImageViewBitmap(R.id.notification_expanded_base_image, songHelper.getAlbumArt());
    notificationView.setImageViewBitmap(R.id.notification_base_image, songHelper.getAlbumArt());

    //Attach the shrunken layout to the notification.
    mNotificationBuilder.setContent(notificationView);

    //Build the notification object.
    Notification notification = mNotificationBuilder.build();

    //Attach the expanded layout to the notification and set its flags.
    notification.bigContentView = expNotificationView;
    notification.flags = Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR
            | Notification.FLAG_ONGOING_EVENT;

    return notification;
}

From source file:com.adityarathi.muo.services.AudioPlaybackService.java

/**
 * Builds and returns a fully constructed Notification for devices 
 * on Ice Cream Sandwich (APIs 14 & 15).
 *//*  ww  w  .  ja v  a2 s.c  o  m*/
private Notification buildICSNotification(SongHelper songHelper) {
    mNotificationBuilder = new NotificationCompat.Builder(mContext);
    mNotificationBuilder.setOngoing(true);
    mNotificationBuilder.setAutoCancel(false);
    mNotificationBuilder.setSmallIcon(R.mipmap.ic_launcher);

    //Open up the player screen when the user taps on the notification.
    Intent launchNowPlayingIntent = new Intent();
    launchNowPlayingIntent.setAction(AudioPlaybackService.LAUNCH_NOW_PLAYING_ACTION);
    PendingIntent launchNowPlayingPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(),
            0, launchNowPlayingIntent, 0);
    mNotificationBuilder.setContentIntent(launchNowPlayingPendingIntent);

    //Grab the notification layout.
    RemoteViews notificationView = new RemoteViews(mContext.getPackageName(),
            R.layout.notification_custom_layout);

    //Initialize the notification layout buttons.
    Intent previousTrackIntent = new Intent();
    previousTrackIntent.setAction(AudioPlaybackService.PREVIOUS_ACTION);
    PendingIntent previousTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            previousTrackIntent, 0);

    Intent playPauseTrackIntent = new Intent();
    playPauseTrackIntent.setAction(AudioPlaybackService.PLAY_PAUSE_ACTION);
    PendingIntent playPauseTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            playPauseTrackIntent, 0);

    Intent nextTrackIntent = new Intent();
    nextTrackIntent.setAction(AudioPlaybackService.NEXT_ACTION);
    PendingIntent nextTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            nextTrackIntent, 0);

    Intent stopServiceIntent = new Intent();
    stopServiceIntent.setAction(AudioPlaybackService.STOP_SERVICE);
    PendingIntent stopServicePendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            stopServiceIntent, 0);

    //Check if audio is playing and set the appropriate play/pause button.
    if (mApp.getService().isPlayingMusic()) {
        notificationView.setImageViewResource(R.id.notification_base_play, R.mipmap.ic_launcher);
    } else {
        notificationView.setImageViewResource(R.id.notification_base_play, R.mipmap.ic_launcher);
    }

    //Set the notification content.    
    notificationView.setTextViewText(R.id.notification_base_line_one, songHelper.getTitle());
    notificationView.setTextViewText(R.id.notification_base_line_two, songHelper.getArtist());

    //Set the states of the next/previous buttons and their pending intents.
    if (mApp.getService().isOnlySongInQueue()) {
        //This is the only song in the queue, so disable the previous/next buttons.
        notificationView.setViewVisibility(R.id.notification_base_next, View.INVISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_previous, View.INVISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);

    } else if (mApp.getService().isFirstSongInQueue()) {
        //This is the the first song in the queue, so disable the previous button. 
        notificationView.setViewVisibility(R.id.notification_base_previous, View.INVISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_next, View.VISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent);

    } else if (mApp.getService().isLastSongInQueue()) {
        //This is the last song in the cursor, so disable the next button.    
        notificationView.setViewVisibility(R.id.notification_base_previous, View.VISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_next, View.INVISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent);

    } else {
        //We're smack dab in the middle of the queue, so keep the previous and next buttons enabled.       
        notificationView.setViewVisibility(R.id.notification_base_previous, View.VISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_next, View.VISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_previous, previousTrackPendingIntent);

    }

    //Set the "Stop Service" pending intent.
    notificationView.setOnClickPendingIntent(R.id.notification_base_collapse, stopServicePendingIntent);

    //Set the album art.
    notificationView.setImageViewBitmap(R.id.notification_base_image, songHelper.getAlbumArt());

    //Attach the shrunken layout to the notification.
    mNotificationBuilder.setContent(notificationView);

    //Build the notification object and set its flags.
    Notification notification = mNotificationBuilder.build();
    notification.flags = Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR
            | Notification.FLAG_ONGOING_EVENT;

    return notification;
}

From source file:com.aniruddhc.acemusic.player.Services.AudioPlaybackService.java

/**
 * Builds and returns a fully constructed Notification for devices 
 * on Ice Cream Sandwich (APIs 14 & 15).
 *//*w w w  .  j av  a 2 s . c o  m*/
private Notification buildICSNotification(SongHelper songHelper) {
    mNotificationBuilder = new NotificationCompat.Builder(mContext);
    mNotificationBuilder.setOngoing(true);
    mNotificationBuilder.setAutoCancel(false);
    mNotificationBuilder.setSmallIcon(R.drawable.notif_icon);

    //Open up the player screen when the user taps on the notification.
    Intent launchNowPlayingIntent = new Intent();
    launchNowPlayingIntent.setAction(AudioPlaybackService.LAUNCH_NOW_PLAYING_ACTION);
    PendingIntent launchNowPlayingPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(),
            0, launchNowPlayingIntent, 0);
    mNotificationBuilder.setContentIntent(launchNowPlayingPendingIntent);

    //Grab the notification layout.
    RemoteViews notificationView = new RemoteViews(mContext.getPackageName(),
            R.layout.notification_custom_layout);

    //Initialize the notification layout buttons.
    Intent previousTrackIntent = new Intent();
    previousTrackIntent.setAction(AudioPlaybackService.PREVIOUS_ACTION);
    PendingIntent previousTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            previousTrackIntent, 0);

    Intent playPauseTrackIntent = new Intent();
    playPauseTrackIntent.setAction(AudioPlaybackService.PLAY_PAUSE_ACTION);
    PendingIntent playPauseTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            playPauseTrackIntent, 0);

    Intent nextTrackIntent = new Intent();
    nextTrackIntent.setAction(AudioPlaybackService.NEXT_ACTION);
    PendingIntent nextTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            nextTrackIntent, 0);

    Intent stopServiceIntent = new Intent();
    stopServiceIntent.setAction(AudioPlaybackService.STOP_SERVICE);
    PendingIntent stopServicePendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0,
            stopServiceIntent, 0);

    //Check if audio is playing and set the appropriate play/pause button.
    if (mApp.getService().isPlayingMusic()) {
        notificationView.setImageViewResource(R.id.notification_base_play, R.drawable.btn_playback_pause_light);
    } else {
        notificationView.setImageViewResource(R.id.notification_base_play, R.drawable.btn_playback_play_light);
    }

    //Set the notification content.    
    notificationView.setTextViewText(R.id.notification_base_line_one, songHelper.getTitle());
    notificationView.setTextViewText(R.id.notification_base_line_two, songHelper.getArtist());

    //Set the states of the next/previous buttons and their pending intents.
    if (mApp.getService().isOnlySongInQueue()) {
        //This is the only song in the queue, so disable the previous/next buttons.
        notificationView.setViewVisibility(R.id.notification_base_next, View.INVISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_previous, View.INVISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);

    } else if (mApp.getService().isFirstSongInQueue()) {
        //This is the the first song in the queue, so disable the previous button. 
        notificationView.setViewVisibility(R.id.notification_base_previous, View.INVISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_next, View.VISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent);

    } else if (mApp.getService().isLastSongInQueue()) {
        //This is the last song in the cursor, so disable the next button.    
        notificationView.setViewVisibility(R.id.notification_base_previous, View.VISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_next, View.INVISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent);

    } else {
        //We're smack dab in the middle of the queue, so keep the previous and next buttons enabled.       
        notificationView.setViewVisibility(R.id.notification_base_previous, View.VISIBLE);
        notificationView.setViewVisibility(R.id.notification_base_next, View.VISIBLE);
        notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent);
        notificationView.setOnClickPendingIntent(R.id.notification_base_previous, previousTrackPendingIntent);

    }

    //Set the "Stop Service" pending intent.
    notificationView.setOnClickPendingIntent(R.id.notification_base_collapse, stopServicePendingIntent);

    //Set the album art.
    notificationView.setImageViewBitmap(R.id.notification_base_image, songHelper.getAlbumArt());

    //Attach the shrunken layout to the notification.
    mNotificationBuilder.setContent(notificationView);

    //Build the notification object and set its flags.
    Notification notification = mNotificationBuilder.build();
    notification.flags = Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR
            | Notification.FLAG_ONGOING_EVENT;

    return notification;
}

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MediaPlaybackService.java

private void updateNotification() {
    RemoteViews views = new RemoteViews(getPackageName(), R.layout.statusbar);
    views.setImageViewResource(R.id.icon, R.drawable.stat_notify_musicplayer);
    if (getAudioId() < 0) {
        // streaming
        views.setTextViewText(R.id.trackname, getPath());
        views.setTextViewText(R.id.artistalbum, null);
    } else {/*from   ww  w.j a va  2s. c o m*/
        String artist = getArtistName();
        views.setTextViewText(R.id.trackname, getTrackName());
        if (artist == null || artist.equals(MediaStore.UNKNOWN_STRING)) {
            artist = getString(R.string.unknown_artist_name);
        }
        String album = getAlbumName();
        if (album == null || album.equals(MediaStore.UNKNOWN_STRING)) {
            album = getString(R.string.unknown_album_name);
        }

        views.setTextViewText(R.id.artistalbum, getString(R.string.notification_artist_album, artist, album));
    }
    Notification status = new Notification();
    status.contentView = views;
    status.flags |= Notification.FLAG_ONGOING_EVENT;
    status.icon = R.drawable.stat_notify_musicplayer;
    status.contentIntent = PendingIntent.getActivity(this, 0,
            new Intent("com.android.music.PLAYBACK_VIEWER").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0);
    startForeground(PLAYBACKSERVICE_STATUS, status);
}

From source file:com.xperia64.timidityae.MusicService.java

public void updateNotification(String title, boolean paused) {
    //System.out.println("Updating notification");

    remoteViews = new RemoteViews(getPackageName(), R.layout.music_notification);
    remoteViews.setTextViewText(R.id.titley, currTitle);
    remoteViews.setImageViewResource(R.id.notPause,
            (paused) ? R.drawable.ic_media_play : R.drawable.ic_media_pause);
    // Previous/*from  w  w w. jav a  2 s  .c  om*/
    Intent new_intent = new Intent();
    //new_intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    new_intent.setAction(getResources().getString(R.string.msrv_rec));
    new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 4);
    PendingIntent pendingNotificationIntent = PendingIntent.getBroadcast(this, 1, new_intent, 0);
    remoteViews.setOnClickPendingIntent(R.id.notPrev, pendingNotificationIntent);
    // Play/Pause
    new_intent = new Intent();
    //new_intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    new_intent.setAction(getResources().getString(R.string.msrv_rec));
    new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 2);
    pendingNotificationIntent = PendingIntent.getBroadcast(this, 2, new_intent, 0);
    remoteViews.setOnClickPendingIntent(R.id.notPause, pendingNotificationIntent);
    // Next
    new_intent = new Intent();
    //new_intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    new_intent.setAction(getResources().getString(R.string.msrv_rec));
    new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 3);
    pendingNotificationIntent = PendingIntent.getBroadcast(this, 3, new_intent, 0);
    remoteViews.setOnClickPendingIntent(R.id.notNext, pendingNotificationIntent);
    // Stop
    new_intent = new Intent();
    //new_intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    new_intent.setAction(getResources().getString(R.string.msrv_rec));
    new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 5);
    pendingNotificationIntent = PendingIntent.getBroadcast(this, 4, new_intent, 0);
    remoteViews.setOnClickPendingIntent(R.id.notStop, pendingNotificationIntent);
    final Intent emptyIntent = new Intent(this, TimidityActivity.class);
    //emptyIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 5, emptyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(getResources().getString(R.string.app_name)).setContentText(currTitle)
            .setContentIntent(pendingIntent).setContent(remoteViews);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        mBuilder.setSmallIcon(R.drawable.ic_lol);
    else
        mBuilder.setSmallIcon(R.drawable.ic_launcher);
    n = mBuilder.build();
    n.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_ONGOING_EVENT;
    if (!foreground) {
        foreground = true;
        startForeground(13901858, n);
        if (!wl.isHeld())
            wl.acquire();

        TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        if (mgr != null) {
            mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
        }
    } else {
        if (!wl.isHeld())
            wl.acquire();
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(13901858, n);
    }
    if (shouldDoWidget) {
        Intent intent = new Intent(this, TimidityAEWidgetProvider.class);
        //Intent intent = new Intent("Ilikepotatoes");
        intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        // Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID,
        // since it seems the onUpdate() is only fired on that:
        //intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
        intent.putExtra("com.xperia64.timidityae.timidityaewidgetprovider.paused", paused);
        intent.putExtra("com.xperia64.timidityae.timidityaewidgetprovider.title", currTitle);
        intent.putExtra("com.xperia64.timidityae.timidityaewidgetprovider.onlyart", true);
        sendBroadcast(intent);
    }
}

From source file:com.andrew.apolloMod.service.ApolloService.java

private void updateNotification() {

    PendingIntent notifIntent = PendingIntent.getActivity(this, 0,
            new Intent("com.andrew.apolloMod.PLAYBACK_VIEWER").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0);

    if (Constants.isApi11Supported()) {
        RemoteViews[] allViews = getNotificationViews();
        RemoteViews bigViews = allViews[0];
        RemoteViews views = allViews[1];

        status = new NotificationCompat.Builder(this).build();
        status.contentView = views;/*from ww w . ja  v  a 2  s.co  m*/
        if (Constants.isApi16Supported()) {
            status.bigContentView = bigViews;
        }
        status.flags = Notification.FLAG_ONGOING_EVENT;
        status.icon = R.drawable.stat_notify_music;
        status.contentIntent = notifIntent;
    } else {
        RemoteViews views = getNotificationViewApi8();

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setContent(views);
        builder.setSmallIcon(R.drawable.stat_notify_music);
        builder.setContentIntent(notifIntent);
        status = builder.build();
        status.contentView = views;
    }
    startForeground(PLAYBACKSERVICE_STATUS, status);
}

From source file:org.mariotaku.harmony.MusicPlaybackService.java

private void startSleepTimer(long milliseconds, boolean gentle) {

    Calendar now = Calendar.getInstance();
    mCurrentTimestamp = now.getTimeInMillis();
    mStopTimestamp = mCurrentTimestamp + milliseconds;

    int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL
            | DateUtils.FORMAT_CAP_AMPM;

    format_flags |= DateUtils.FORMAT_SHOW_TIME;
    String time = DateUtils.formatDateTime(this, mStopTimestamp, format_flags);

    CharSequence contentTitle = getString(R.string.sleep_timer_enabled);
    CharSequence contentText = getString(R.string.notification_sleep_timer, time);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
    Notification notification = new Notification(R.drawable.ic_stat_playback, null, 0);
    notification.flags = Notification.FLAG_ONGOING_EVENT;
    notification.icon = R.drawable.ic_stat_sleeptimer;
    notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);

    mGentleSleepTimer = gentle;//from   w  w  w. java 2 s  .  c  o  m
    mNotificationManager.notify(ID_NOTIFICATION_SLEEPTIMER, notification);
    mSleepTimerHandler.sendEmptyMessageDelayed(START_SLEEP_TIMER, milliseconds);
    final int nmin = (int) milliseconds / 60 / 1000;
    Toast.makeText(this, getResources().getQuantityString(R.plurals.NNNminutes_notif, nmin, nmin),
            Toast.LENGTH_SHORT).show();
}

From source file:mp.teardrop.PlaybackService.java

/**
 * Create a song notification. Call through the NotificationManager to
 * display it./*from  w w  w. ja  v  a 2s . c o m*/
 *
 * @param song The Song to display information about.
 * @param state The state. Determines whether to show paused or playing icon.
 */
public Notification createNotification(Song song, int state) {
    boolean playing = (state & FLAG_PLAYING) != 0;

    RemoteViews views = new RemoteViews(getPackageName(), R.layout.notification);
    RemoteViews expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded);

    Bitmap cover = song.getCover(this);
    if (cover == null) {
        views.setImageViewResource(R.id.cover, R.drawable.fallback_cover);
        expanded.setImageViewResource(R.id.cover, R.drawable.fallback_cover);
    } else {
        views.setImageViewBitmap(R.id.cover, cover);
        expanded.setImageViewBitmap(R.id.cover, cover);
    }

    int playButton = getPlayButtonResource(playing);

    views.setImageViewResource(R.id.play_pause, playButton);
    expanded.setImageViewResource(R.id.play_pause, playButton);

    ComponentName service = new ComponentName(this, PlaybackService.class);

    Intent previous = new Intent(PlaybackService.ACTION_PREVIOUS_SONG);
    previous.setComponent(service);
    expanded.setOnClickPendingIntent(R.id.previous, PendingIntent.getService(this, 0, previous, 0));

    Intent playPause = new Intent(PlaybackService.ACTION_TOGGLE_PLAYBACK_NOTIFICATION);
    playPause.setComponent(service);
    views.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getService(this, 0, playPause, 0));
    expanded.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getService(this, 0, playPause, 0));

    Intent next = new Intent(PlaybackService.ACTION_NEXT_SONG);
    next.setComponent(service);
    views.setOnClickPendingIntent(R.id.next, PendingIntent.getService(this, 0, next, 0));
    expanded.setOnClickPendingIntent(R.id.next, PendingIntent.getService(this, 0, next, 0));

    Intent close = new Intent(PlaybackService.ACTION_CLOSE_NOTIFICATION);
    close.setComponent(service);
    views.setOnClickPendingIntent(R.id.close, PendingIntent.getService(this, 0, close, 0));
    expanded.setOnClickPendingIntent(R.id.close, PendingIntent.getService(this, 0, close, 0));

    views.setTextViewText(R.id.title, song.title);
    views.setTextViewText(R.id.artist, song.artist);
    expanded.setTextViewText(R.id.title, song.title);
    expanded.setTextViewText(R.id.album, song.album);
    expanded.setTextViewText(R.id.artist, song.artist);

    Notification notification = new Notification();
    notification.contentView = views;
    notification.icon = R.drawable.status_icon;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notification.contentIntent = mNotificationAction;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        // expanded view is available since 4.1
        notification.bigContentView = expanded;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notification.visibility = Notification.VISIBILITY_PUBLIC;
    }

    //        if(mNotificationNag) {
    //            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    //                notification.priority = Notification.PRIORITY_MAX;
    //                notification.vibrate = new long[0]; // needed to get headsup
    //            } else {
    //                notification.tickerText = song.title + " - " + song.artist;
    //            }
    //        }

    return notification;
}

From source file:com.mobicage.rogerthat.plugins.messaging.MessagingPlugin.java

private void showTransferPendingNotification(String notificationMessage) {
    T.dontCare();/*from   ww w. j  a  v a 2s .  c  o m*/
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mMainService)
            .setContentTitle(mMainService.getString(R.string.app_name)).setContentText(notificationMessage)
            .setSmallIcon(R.drawable.ic_menu_upload)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationMessage)).setAutoCancel(false);

    final NotificationManager nm = (NotificationManager) mMainService
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = mBuilder.build();
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notification.flags &= ~Notification.FLAG_AUTO_CANCEL;

    Intent i = new Intent(MainActivity.ACTION_NOTIFICATION_OPEN_APP, null, mMainService, MainActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pi = PendingIntent.getActivity(mMainService, 1000, i, PendingIntent.FLAG_UPDATE_CURRENT);

    notification.contentIntent = pi;

    nm.notify(R.integer.photo_upload_pending, notification);
}