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:com.dmplayer.manager.MusicPlayerService.java

@SuppressLint("NewApi")
private void createNotification(SongDetail mSongDetail) {
    try {//from   ww w.jav a 2s.  com
        String songName = mSongDetail.getTitle();
        String authorName = mSongDetail.getArtist();
        SongDetail audioInfo = MediaController.getInstance().getPlayingSongDetail();

        RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(),
                R.layout.player_small_notification);
        RemoteViews expandedView = null;
        if (supportBigNotifications) {
            expandedView = new RemoteViews(getApplicationContext().getPackageName(),
                    R.layout.player_big_notification);
        }

        Intent intent = new Intent(ApplicationDMPlayer.applicationContext, DMPlayerBaseActivity.class);
        intent.setAction("openplayer");
        intent.setFlags(32768);
        PendingIntent contentIntent = PendingIntent.getActivity(ApplicationDMPlayer.applicationContext, 0,
                intent, 0);

        Notification notification = new NotificationCompat.Builder(getApplicationContext())
                .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName)
                .build();

        notification.contentView = simpleContentView;
        if (supportBigNotifications) {
            notification.bigContentView = expandedView;
        }

        setListeners(simpleContentView);
        if (supportBigNotifications) {
            setListeners(expandedView);
        }

        Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover(ApplicationDMPlayer.applicationContext)
                : null;

        if (albumArt != null) {
            notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt);
            if (supportBigNotifications) {
                notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt);
            }
        } else {
            notification.contentView.setImageViewResource(R.id.player_album_art,
                    R.drawable.bg_default_album_art);
            if (supportBigNotifications) {
                notification.bigContentView.setImageViewResource(R.id.player_album_art,
                        R.drawable.bg_default_album_art);
            }
        }
        notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE);
        notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
        if (supportBigNotifications) {
            notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        }

        if (MediaController.getInstance().isAudioPaused()) {
            notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
            notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            }
        } else {
            notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
            notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
            }
        }

        notification.contentView.setTextViewText(R.id.player_song_name, songName);
        notification.contentView.setTextViewText(R.id.player_author_name, authorName);
        if (supportBigNotifications) {
            notification.bigContentView.setTextViewText(R.id.player_song_name, songName);
            notification.bigContentView.setTextViewText(R.id.player_author_name, authorName);
        }
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
        startForeground(5, notification);

        if (remoteControlClient != null) {
            RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName);
            if (audioInfo != null && audioInfo.getCover(ApplicationDMPlayer.applicationContext) != null) {
                metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK,
                        audioInfo.getCover(ApplicationDMPlayer.applicationContext));
            }
            metadataEditor.apply();
            audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.mantraideas.androidaudio.manager.MusicPlayerService.java

@SuppressLint("NewApi")
private void createNotification(SongDetail mSongDetail) {
    try {// www .j  a  v a 2 s .  c  o m
        String songName = mSongDetail.getTitle();
        String authorName = mSongDetail.getArtist();
        SongDetail audioInfo = MediaController.getInstance().getPlayingSongDetail();

        RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(),
                R.layout.player_small_notification);
        RemoteViews expandedView = null;
        if (supportBigNotifications) {
            expandedView = new RemoteViews(getApplicationContext().getPackageName(),
                    R.layout.player_big_notification);
        }

        Intent intent = new Intent(MyApplication.applicationContext, MainActivity.class);
        intent.setAction("openplayer");
        intent.setFlags(32768);
        PendingIntent contentIntent = PendingIntent.getActivity(MyApplication.applicationContext, 0, intent, 0);

        Notification notification = new NotificationCompat.Builder(getApplicationContext())
                .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName)
                .build();

        notification.contentView = simpleContentView;
        if (supportBigNotifications) {
            notification.bigContentView = expandedView;
        }

        setListeners(simpleContentView);
        if (supportBigNotifications) {
            setListeners(expandedView);
        }

        Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover(MyApplication.applicationContext) : null;

        if (albumArt != null) {
            notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt);
            if (supportBigNotifications) {
                notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt);
            }
        } else {
            notification.contentView.setImageViewResource(R.id.player_album_art,
                    R.drawable.bg_default_album_art);
            if (supportBigNotifications) {
                notification.bigContentView.setImageViewResource(R.id.player_album_art,
                        R.drawable.bg_default_album_art);
            }
        }
        notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE);
        notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
        if (supportBigNotifications) {
            notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        }

        if (MediaController.getInstance().isAudioPaused()) {
            notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
            notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            }
        } else {
            notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
            notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
            }
        }

        notification.contentView.setTextViewText(R.id.player_song_name, songName);
        notification.contentView.setTextViewText(R.id.player_author_name, authorName);
        if (supportBigNotifications) {
            notification.bigContentView.setTextViewText(R.id.player_song_name, songName);
            notification.bigContentView.setTextViewText(R.id.player_author_name, authorName);
        }
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
        startForeground(5, notification);

        if (remoteControlClient != null) {
            RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName);
            if (audioInfo != null && audioInfo.getCover(MyApplication.applicationContext) != null) {
                metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK,
                        audioInfo.getCover(MyApplication.applicationContext));
            }
            metadataEditor.apply();
            audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.sf.asap.PlayerService.java

public void run() {
    // read file/* ww w . j ava 2  s . c  o  m*/
    String filename = uri.getPath();
    byte[] module = new byte[ASAPInfo.MAX_MODULE_LENGTH];
    int moduleLen;
    try {
        InputStream is;
        switch (uri.getScheme()) {
        case "file":
            if (Util.isZip(filename)) {
                String zipFilename = filename;
                filename = uri.getFragment();
                is = new ZipInputStream(zipFilename, filename);
            } else
                is = new FileInputStream(filename);
            break;
        case "http":
            is = httpGet(uri);
            break;
        default:
            throw new FileNotFoundException(uri.toString());
        }
        moduleLen = Util.readAndClose(is, module);
    } catch (IOException ex) {
        showError(R.string.error_reading_file);
        return;
    }

    // load file
    try {
        asap.load(filename, module, moduleLen);
        info = asap.getInfo();
        switch (song) {
        case SONG_DEFAULT:
            song = info.getDefaultSong();
            break;
        case SONG_LAST:
            song = info.getSongs() - 1;
            break;
        default:
            break;
        }
        playSong();
    } catch (Exception ex) {
        showError(R.string.invalid_file);
        return;
    }

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Player.class), 0);
    String title = info.getTitleOrFilename();
    Notification notification = new Notification(R.drawable.icon, title, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notification.setLatestEventInfo(this, title, info.getAuthor(), contentIntent);
    startForegroundCompat(NOTIFICATION_ID, notification);

    // playback
    int channelConfig = info.getChannels() == 1 ? AudioFormat.CHANNEL_CONFIGURATION_MONO
            : AudioFormat.CHANNEL_CONFIGURATION_STEREO;
    int bufferLen = AudioTrack.getMinBufferSize(ASAP.SAMPLE_RATE, channelConfig,
            AudioFormat.ENCODING_PCM_16BIT) >> 1;
    if (bufferLen < 16384)
        bufferLen = 16384;
    final byte[] byteBuffer = new byte[bufferLen << 1];
    final short[] shortBuffer = new short[bufferLen];
    audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, ASAP.SAMPLE_RATE, channelConfig,
            AudioFormat.ENCODING_PCM_16BIT, bufferLen << 1, AudioTrack.MODE_STREAM);
    audioTrack.play();

    for (;;) {
        synchronized (this) {
            if (bufferLen < shortBuffer.length || isPaused()) {
                try {
                    wait();
                } catch (InterruptedException ex) {
                }
            }
            if (stop) {
                audioTrack.stop();
                return;
            }
        }
        synchronized (asap) {
            int pos = seekPosition;
            if (pos >= 0) {
                seekPosition = -1;
                try {
                    asap.seek(pos);
                } catch (Exception ex) {
                }
            }
            bufferLen = asap.generate(byteBuffer, byteBuffer.length, ASAPSampleFormat.S16_L_E) >> 1;
        }
        for (int i = 0; i < bufferLen; i++)
            shortBuffer[i] = (short) ((byteBuffer[i << 1] & 0xff) | byteBuffer[i << 1 | 1] << 8);
        audioTrack.write(shortBuffer, 0, bufferLen);
    }
}

From source file:com.marianhello.cordova.bgloc.LocationUpdateService.java

@Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i(TAG, "Received start id " + startId + ": " + intent);
        if (intent != null) {
            try {
                params = new JSONObject(intent.getStringExtra("params"));
                headers = new JSONObject(intent.getStringExtra("headers"));
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();//from w w  w  . j a  v  a 2 s  .  co  m
            }
            url = intent.getStringExtra("url");
            stationaryRadius = Float.parseFloat(intent.getStringExtra("stationaryRadius"));
            distanceFilter = Integer.parseInt(intent.getStringExtra("distanceFilter"));
            scaledDistanceFilter = distanceFilter;
            desiredAccuracy = Integer.parseInt(intent.getStringExtra("desiredAccuracy"));
            locationTimeout = Integer.parseInt(intent.getStringExtra("locationTimeout"));
            isDebugging = Boolean.parseBoolean(intent.getStringExtra("isDebugging"));
            notificationTitle = intent.getStringExtra("notificationTitle");
            notificationText = intent.getStringExtra("notificationText");

            // Build a Notification required for running service in foreground.
            Intent main = new Intent(this, BackgroundGpsPlugin.class);
            main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, main,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            Notification.Builder builder = new Notification.Builder(this);
            builder.setContentTitle(notificationTitle);
            builder.setContentText(notificationText);
            builder.setSmallIcon(android.R.drawable.ic_menu_mylocation);
            builder.setContentIntent(pendingIntent);
            Notification notification;
            if (android.os.Build.VERSION.SDK_INT >= 16) {
                notification = buildForegroundNotification(builder);
            } else {
                notification = buildForegroundNotificationCompat(builder);
            }
            notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE
                    | Notification.FLAG_NO_CLEAR;
            startForeground(startId, notification);
        }
        Log.i(TAG, "- url: " + url);
        Log.i(TAG, "- params: " + params.toString());
        Log.i(TAG, "- headers: " + headers.toString());
        Log.i(TAG, "- stationaryRadius: " + stationaryRadius);
        Log.i(TAG, "- distanceFilter: " + distanceFilter);
        Log.i(TAG, "- desiredAccuracy: " + desiredAccuracy);
        Log.i(TAG, "- locationTimeout: " + locationTimeout);
        Log.i(TAG, "- isDebugging: " + isDebugging);
        Log.i(TAG, "- notificationTitle: " + notificationTitle);
        Log.i(TAG, "- notificationText: " + notificationText);

        this.setPace(false);

        //We want this service to continue running until it is explicitly stopped
        return START_REDELIVER_INTENT;
    }

From source file:kz.qobyzbook.manager.MusicPlayerService.java

@SuppressLint("NewApi")
private void createNotification(SongDetail mSongDetail) {
    try {/*  w  ww  .  j  av a2 s. c o m*/
        String songName = mSongDetail.getTitle();
        String authorName = mSongDetail.getArtist();
        String songImage = mSongDetail.getImage_url();
        SongDetail audioInfo = MediaController.getInstance().getPlayingSongDetail();

        RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(),
                R.layout.player_small_notification);
        RemoteViews expandedView = null;
        if (supportBigNotifications) {
            expandedView = new RemoteViews(getApplicationContext().getPackageName(),
                    R.layout.player_big_notification);
        }

        Intent intent = new Intent(ApplicationDMPlayer.applicationContext, DMPlayerBaseActivity.class);
        intent.setAction("openplayer");
        intent.setFlags(32768);
        PendingIntent contentIntent = PendingIntent.getActivity(ApplicationDMPlayer.applicationContext, 0,
                intent, 0);

        Notification notification = new NotificationCompat.Builder(getApplicationContext())
                .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName)
                .build();

        notification.contentView = simpleContentView;
        if (supportBigNotifications) {
            notification.bigContentView = expandedView;
        }

        setListeners(simpleContentView);
        if (supportBigNotifications) {
            setListeners(expandedView);
        }

        Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover(ApplicationDMPlayer.applicationContext)
                : null;

        if (albumArt != null) {
            notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt);
            if (supportBigNotifications) {
                notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt);
            }
        } else {
            notification.contentView.setImageViewResource(R.id.player_album_art,
                    R.drawable.bg_default_album_art);
            if (supportBigNotifications) {
                notification.bigContentView.setImageViewResource(R.id.player_album_art,
                        R.drawable.bg_default_album_art);
            }
        }
        notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE);
        notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
        if (supportBigNotifications) {
            notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        }

        if (MediaController.getInstance().isAudioPaused()) {
            notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
            notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            }
        } else {
            notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
            notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
            }
        }

        notification.contentView.setTextViewText(R.id.player_song_name, songName);
        notification.contentView.setTextViewText(R.id.player_author_name, authorName);
        if (supportBigNotifications) {
            notification.bigContentView.setTextViewText(R.id.player_song_name, songName);
            notification.bigContentView.setTextViewText(R.id.player_author_name, authorName);
            //                notification.bigContentView.setTextViewText(R.id.player_albumname, albumName);
        }
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
        startForeground(5, notification);

        if (remoteControlClient != null) {
            RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName);
            if (audioInfo != null && audioInfo.getCover(ApplicationDMPlayer.applicationContext) != null) {
                metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK,
                        audioInfo.getCover(ApplicationDMPlayer.applicationContext));
            }
            metadataEditor.apply();
            audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:co.codecrunch.musicplayerlite.manager.MusicPlayerService.java

@SuppressLint("NewApi")
private void createNotification(SongDetail mSongDetail) {
    try {//from  w  ww  .j a  v a 2s.c om
        String songName = mSongDetail.getTitle();
        String authorName = mSongDetail.getArtist();
        String albumName = mSongDetail.getDisplay_name();
        SongDetail audioInfo = MediaController.getInstance().getPlayingSongDetail();

        RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(),
                R.layout.player_small_notification);
        RemoteViews expandedView = null;
        if (supportBigNotifications) {
            expandedView = new RemoteViews(getApplicationContext().getPackageName(),
                    R.layout.player_big_notification);
        }

        Intent intent = new Intent(ApplicationMusicPlayer.applicationContext, MusicPlayerBaseActivity.class);
        intent.setAction("openplayer");
        intent.setFlags(32768);
        PendingIntent contentIntent = PendingIntent.getActivity(ApplicationMusicPlayer.applicationContext, 0,
                intent, 0);

        Notification notification = new NotificationCompat.Builder(getApplicationContext())
                .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName)
                .build();

        notification.contentView = simpleContentView;
        if (supportBigNotifications) {
            notification.bigContentView = expandedView;
        }

        setListeners(simpleContentView);
        if (supportBigNotifications) {
            setListeners(expandedView);
        }

        Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover(ApplicationMusicPlayer.applicationContext)
                : null;

        if (albumArt != null) {
            notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt);
            if (supportBigNotifications) {
                notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt);
            }
        } else {
            notification.contentView.setImageViewResource(R.id.player_album_art,
                    R.drawable.bg_default_album_art);
            if (supportBigNotifications) {
                notification.bigContentView.setImageViewResource(R.id.player_album_art,
                        R.drawable.bg_default_album_art);
            }
        }
        notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE);
        notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
        if (supportBigNotifications) {
            notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        }

        if (MediaController.getInstance().isAudioPaused()) {
            notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
            notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            }
        } else {
            notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
            notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
            }
        }

        notification.contentView.setTextViewText(R.id.player_song_name, songName);
        notification.contentView.setTextViewText(R.id.player_author_name, authorName);
        if (supportBigNotifications) {
            notification.bigContentView.setTextViewText(R.id.player_song_name, songName);
            notification.bigContentView.setTextViewText(R.id.player_author_name, authorName);
            //                notification.bigContentView.setTextViewText(R.id.player_albumname, albumName);
        }
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
        startForeground(5, notification);

        if (remoteControlClient != null) {
            RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName);
            if (audioInfo != null && audioInfo.getCover(ApplicationMusicPlayer.applicationContext) != null) {
                metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK,
                        audioInfo.getCover(ApplicationMusicPlayer.applicationContext));
            }
            metadataEditor.apply();
            audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:in.risysnetworks.shplayer.mediacontroller.MusicPlayerService.java

@SuppressLint("NewApi")
private void createNotification(SongDetail mSongDetail) {
    try {//  w  ww  . j  a  v  a 2  s. c o m
        String songName = mSongDetail.getTitle();
        String authorName = mSongDetail.getArtist();
        SongDetail audioInfo = MediaController.getInstance().getPlayingSongDetail();

        RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(),
                R.layout.player_small_notification);
        RemoteViews expandedView = null;
        if (supportBigNotifications) {
            expandedView = new RemoteViews(getApplicationContext().getPackageName(),
                    R.layout.player_big_notification);
        }

        Intent intent = new Intent(ApplicationSHPlayer.applicationContext, SHPlayerMainActivity.class);
        intent.setAction("openplayer");
        intent.setFlags(32768);
        PendingIntent contentIntent = PendingIntent.getActivity(ApplicationSHPlayer.applicationContext, 0,
                intent, 0);

        Notification notification = new NotificationCompat.Builder(getApplicationContext())
                .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName)
                .build();

        if (supportBigNotifications) {
            notification.bigContentView = expandedView;
        } else {
            notification.contentView = simpleContentView;
        }

        if (supportBigNotifications) {
            setListeners(expandedView);
        } else {
            setListeners(simpleContentView);
        }

        Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover(ApplicationSHPlayer.applicationContext)
                : null;

        if (albumArt != null) {

            if (supportBigNotifications) {
                notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt);
            } else {
                notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt);
            }
        } else {

            if (supportBigNotifications) {
                notification.bigContentView.setImageViewResource(R.id.player_album_art,
                        R.drawable.bg_default_album_art);
            } else {
                notification.contentView.setImageViewResource(R.id.player_album_art,
                        R.drawable.bg_default_album_art);
            }
        }

        if (supportBigNotifications) {
            notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        } else {
            notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
            notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE);
            notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
        }

        if (MediaController.getInstance().isAudioPaused()) {

            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            } else {
                notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
                notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            }
        } else {

            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
            } else {
                notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
                notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
            }
        }

        if (supportBigNotifications) {
            notification.bigContentView.setTextViewText(R.id.player_song_name, songName);
            notification.bigContentView.setTextViewText(R.id.player_author_name, authorName);
        } else {
            notification.contentView.setTextViewText(R.id.player_song_name, songName);
            notification.contentView.setTextViewText(R.id.player_author_name, authorName);
        }
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
        startForeground(5, notification);

        if (remoteControlClient != null) {
            RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName);
            if (audioInfo != null && audioInfo.getCover(ApplicationSHPlayer.applicationContext) != null) {
                metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK,
                        audioInfo.getCover(ApplicationSHPlayer.applicationContext));
            }
            metadataEditor.apply();
            audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
        }
    } catch (Exception e) {
        e.printStackTrace();

        System.out.println(" error --> " + e.toString());
    }
}

From source file:net.micode.soundrecorder.RecorderService.java

private void showRecordingNotification() {

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.stat_sys_call_record).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.notification_recording));

    Intent notificationIntent = new Intent(this, SoundRecorder.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(contentIntent);
    Notification noti = mBuilder.build();
    noti.flags = Notification.FLAG_ONGOING_EVENT;
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(notifyID, noti);//from  w  ww.j  a  va2 s. com

}

From source file:org.linphone.LinphoneService.java

@Override
public void onCreate() {
    super.onCreate();
    theLinphone = this;

    // Dump some debugging information to the logs
    Hacks.dumpDeviceInformation();/*from  www. j av a 2  s . com*/
    addCallListner();
    //      tryTogetLastReceive();
    //      tryTogetLastRequest();
    tryKeepOnline();
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotification = new Notification(R.drawable.status_level, "", System.currentTimeMillis());
    mNotification.iconLevel = IC_LEVEL_ORANGE;
    mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
    Intent notificationIntent = new Intent(this, MainViewActivity.class);
    mNofificationContentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    mNotification.setLatestEventInfo(this, NOTIFICATION_TITLE, "", mNofificationContentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mNotification);
    mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    mAudioManager = ((AudioManager) getSystemService(Context.AUDIO_SERVICE));
    mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    try {
        copyAssetsFromPackage();

        mLinphoneCore = LinphoneCoreFactory.instance().createLinphoneCore(this, LINPHONE_RC,
                LINPHONE_FACTORY_RC, null);

        mLinphoneCore.setPlaybackGain(3);
        mLinphoneCore.setRing(null);

        try {
            initFromConf();
        } catch (LinphoneException e) {
            Log.w(TAG, "no config ready yet");
        }
        TimerTask lTask = new TimerTask() {
            @Override
            public void run() {
                mLinphoneCore.iterate();
            }

        };

        mTimer.scheduleAtFixedRate(lTask, 0, 100);
        IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
        lFilter.addAction(Intent.ACTION_SCREEN_OFF);
        registerReceiver(mKeepAliveMgrReceiver, lFilter);

    } catch (Exception e) {
        Log.e(TAG, "Cannot start linphone", e);
    }

}

From source file:com.goftagram.telegram.messenger.MusicPlayerService.java

@SuppressLint("NewApi")
private void createNotification(MessageObject messageObject) {
    String songName = messageObject.getMusicTitle();
    String authorName = messageObject.getMusicAuthor();
    AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();

    RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(),
            R.layout.player_small_notification);
    RemoteViews expandedView = null;/*  ww  w  .j  a v a  2 s  .co m*/
    if (supportBigNotifications) {
        expandedView = new RemoteViews(getApplicationContext().getPackageName(),
                R.layout.player_big_notification);
    }

    Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
    intent.setAction("com.tmessages.openplayer");
    intent.setFlags(32768);
    PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, 0);

    Notification notification = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName).build();

    notification.contentView = simpleContentView;
    if (supportBigNotifications) {
        notification.bigContentView = expandedView;
    }

    setListeners(simpleContentView);
    if (supportBigNotifications) {
        setListeners(expandedView);
    }

    Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover() : null;
    if (albumArt != null) {
        notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt);
        if (supportBigNotifications) {
            notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt);
        }
    } else {
        notification.contentView.setImageViewResource(R.id.player_album_art, R.drawable.nocover_small);
        if (supportBigNotifications) {
            notification.bigContentView.setImageViewResource(R.id.player_album_art, R.drawable.nocover_big);
        }
    }
    if (MediaController.getInstance().isDownloadingCurrentMessage()) {
        notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_next, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_previous, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE);
        if (supportBigNotifications) {
            notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
            notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
            notification.bigContentView.setViewVisibility(R.id.player_next, View.GONE);
            notification.bigContentView.setViewVisibility(R.id.player_previous, View.GONE);
            notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE);
        }
    } else {
        notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE);
        notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
        if (supportBigNotifications) {
            notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
            notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
        }

        if (MediaController.getInstance().isAudioPaused()) {
            notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
            notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE);
            }
        } else {
            notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
            notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
            if (supportBigNotifications) {
                notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
                notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
            }
        }
    }

    notification.contentView.setTextViewText(R.id.player_song_name, songName);
    notification.contentView.setTextViewText(R.id.player_author_name, authorName);
    if (supportBigNotifications) {
        notification.bigContentView.setTextViewText(R.id.player_song_name, songName);
        notification.bigContentView.setTextViewText(R.id.player_author_name, authorName);
    }
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(5, notification);

    if (remoteControlClient != null) {
        RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
        metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName);
        metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName);
        if (audioInfo != null && audioInfo.getCover() != null) {
            metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK,
                    audioInfo.getCover());
        }
        metadataEditor.apply();
        audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    }
}