androidx.media.session.MediaButtonReceiver Java Examples

The following examples show how to use androidx.media.session.MediaButtonReceiver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServicePlayMusic.java    From Bop with Apache License 2.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    if (intent != null) {
        String action = intent.getAction();
        String command = intent.getStringExtra(CMD_NAME);
        if (ACTION_CMD.equals(action)) {
            if (ACTION_PAUSE.equals(command)) {
                pausePlayer();
            }
        } else {
            MediaButtonReceiver.handleIntent(mMediaSessionCompat, intent);
        }
    }
    mDelayedStopHandler.removeCallbacksAndMessages(null);
    mDelayedStopHandler.sendEmptyMessageDelayed(0, STOP_DELAY);

    return START_STICKY;
}
 
Example #2
Source File: VinylCastService.java    From vinyl-cast with MIT License 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Timber.d("onStartCommand");

    if (castSessionManagerListener == null) {
        castSessionManagerListener = new CastSessionManagerListener();
        ((VinylCastApplication)getApplication()).getCastSessionManager().addSessionManagerListener(castSessionManagerListener);
    }

    String action = intent.getAction();
    Timber.d("onStartCommand received action: " + action);

    switch (action) {
        case VinylCastService.ACTION_START_RECORDING:
            engage();
            break;
        case VinylCastService.ACTION_STOP_RECORDING:
            disengage(false);
            break;
        default:
            MediaButtonReceiver.handleIntent(mediaSession, intent);
            break;
    }

    return START_NOT_STICKY;
}
 
Example #3
Source File: MediaStyleHelper.java    From AndroidAudioExample with MIT License 6 votes vote down vote up
/**
 * Build a notification using the information from the given media session. Makes heavy use
 * of {@link MediaMetadataCompat#getDescription()} to extract the appropriate information.
 *
 * @param context      Context used to construct the notification.
 * @param mediaSession Media session to get information.
 * @return A pre-built notification with information from the given media session.
 */
static NotificationCompat.Builder from(Context context, MediaSessionCompat mediaSession) {
    MediaControllerCompat controller = mediaSession.getController();
    MediaMetadataCompat mediaMetadata = controller.getMetadata();
    MediaDescriptionCompat description = mediaMetadata.getDescription();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder
            .setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle())
            .setSubText(description.getDescription())
            .setLargeIcon(description.getIconBitmap())
            .setContentIntent(controller.getSessionActivity())
            .setDeleteIntent(
                    MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_STOP))
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    return builder;
}
 
Example #4
Source File: PlayerService.java    From Jockey with Apache License 2.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Timber.i("onStartCommand called");
    super.onStartCommand(intent, flags, startId);

    if (intent != null && MediaStoreUtil.hasPermission(this)) {
        if (mBeQuiet) {
            mBeQuiet = intent.getBooleanExtra(EXTRA_START_SILENT, true);
        }

        if (intent.hasExtra(Intent.EXTRA_KEY_EVENT)) {
            notifyNowPlaying(true);
            MediaButtonReceiver.handleIntent(musicPlayer.getMediaSession(), intent);
            Timber.i(intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT).toString());
        }
    }
    return START_STICKY;
}
 
Example #5
Source File: MusicPlayer.java    From Jockey with Apache License 2.0 6 votes vote down vote up
/**
 * Initiate a MediaSession to allow the Android system to interact with the player
 */
private void initMediaSession() {
    Timber.i("Initializing MediaSession");
    ComponentName mbrComponent = new ComponentName(mContext, MediaButtonReceiver.class.getName());
    mMediaSession = new MediaSessionCompat(mContext, TAG, mbrComponent, null);
    mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
            | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);

    mMediaSession.setCallback(new MediaSessionCallback(this, mMediaBrowserRoot));
    mMediaSession.setSessionActivity(
            PendingIntent.getActivity(
                    mContext, 0,
                    LibraryActivity.newNowPlayingIntent(mContext)
                            .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
                    PendingIntent.FLAG_CANCEL_CURRENT));

    updateMediaSession();

    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setClass(mContext, MediaButtonReceiver.class);
    PendingIntent mbrIntent = PendingIntent.getBroadcast(mContext, 0, mediaButtonIntent, 0);
    mMediaSession.setMediaButtonReceiver(mbrIntent);

    mMediaSession.setActive(true);
}
 
Example #6
Source File: PlayerService.java    From AndroidAudioExample with MIT License 6 votes vote down vote up
private Notification getNotification(int playbackState) {
    NotificationCompat.Builder builder = MediaStyleHelper.from(this, mediaSession);
    builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_previous, getString(R.string.previous), MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)));

    if (playbackState == PlaybackStateCompat.STATE_PLAYING)
        builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_pause, getString(R.string.pause), MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_PLAY_PAUSE)));
    else
        builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_play, getString(R.string.play), MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_PLAY_PAUSE)));

    builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_next, getString(R.string.next), MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_SKIP_TO_NEXT)));
    builder.setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
            .setShowActionsInCompactView(1)
            .setShowCancelButton(true)
            .setCancelButtonIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_STOP))
            .setMediaSession(mediaSession.getSessionToken())); // setMediaSession требуется для Android Wear
    builder.setSmallIcon(R.mipmap.ic_launcher);
    builder.setColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)); // The whole background (in MediaStyle), not just icon background
    builder.setShowWhen(false);
    builder.setPriority(NotificationCompat.PRIORITY_HIGH);
    builder.setOnlyAlertOnce(true);
    builder.setChannelId(NOTIFICATION_DEFAULT_CHANNEL_ID);

    return builder.build();
}
 
Example #7
Source File: MediaPlaybackService.java    From react-native-jw-media-player with MIT License 5 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
	if (mMediaSessionManager != null) {
		MediaButtonReceiver.handleIntent(mMediaSessionManager.getMediaSession(), intent);
	}
	return START_STICKY;
}
 
Example #8
Source File: TtsService.java    From android-app with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(TAG, "onStartCommand() " + intent);

    if (intent != null) {
        if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
            // `MediaButtonReceiver` may use `Context.startForegroundService(Intent)`,
            // so we *have* to call `startForeground(...)`
            // or the app will crash during service shutdown

            setForegroundAndNotification(true);
        }

        MediaButtonReceiver.handleIntent(mediaSession, intent);

        String action = intent.getAction();
        if (ACTION_PLAY.equals(action)) {
            playCmd();
        } else if (ACTION_PAUSE.equals(action)) {
            pauseCmd();
        } else if (ACTION_PLAY_PAUSE.equals(action)) {
            playPauseCmd();
        } else if (ACTION_REWIND.equals(action)) {
            rewindCmd();
        } else if (ACTION_FAST_FORWARD.equals(action)) {
            fastForwardCmd();
        }
    }

    return super.onStartCommand(intent, flags, startId);
}
 
Example #9
Source File: PlayerService.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private void addNotificationAction(NotificationCompat.Builder builder,
                                   @DrawableRes int icon, @StringRes int string,
                                   @MediaKeyAction long action) {

    PendingIntent intent = MediaButtonReceiver.buildMediaButtonPendingIntent(this, action);
    builder.addAction(new NotificationCompat.Action(icon, getString(string), intent));
}
 
Example #10
Source File: PlayerService.java    From Jockey with Apache License 2.0 5 votes vote down vote up
/**
 * Generate and post a notification for the current player status
 * Posts the notification by starting the service in the foreground
 */
private void notifyNowPlaying(boolean foreground) {
    Timber.i("notifyNowPlaying called");

    if (musicPlayer == null || musicPlayer.getMediaSession() == null) {
        Timber.i("Not showing notification. Media session is uninitialized");
        return;
    }

    if (mBeQuiet) {
        mBeQuiet = !musicPlayer.isPlaying();
    }

    NotificationCompat.Builder builder = MediaStyleHelper.from(
            this,
            musicPlayer.getMediaSession(),
            NOTIFICATION_CHANNEL_ID
    );

    setupNotificationActions(builder);

    PendingIntent stopIntent = MediaButtonReceiver.buildMediaButtonPendingIntent(this,
            PlaybackStateCompat.ACTION_STOP);

    builder.setSmallIcon(getNotificationIcon())
            .setDeleteIntent(stopIntent)
            .setStyle(
                    new MediaStyle()
                            .setShowActionsInCompactView(0, 1, 2)
                            .setShowCancelButton(true)
                            .setCancelButtonIntent(stopIntent)
                            .setMediaSession(musicPlayer.getMediaSession().getSessionToken()));

    showNotification(builder.build(), foreground);
}
 
Example #11
Source File: MusicService.java    From klingar with Apache License 2.0 5 votes vote down vote up
@Override public int onStartCommand(Intent startIntent, int flags, int startId) {
  if (startIntent != null) {
    if (ACTION_STOP_CASTING.equals(startIntent.getAction())) {
      CastContext.getSharedInstance(this).getSessionManager().endCurrentSession(true);
    } else {
      // Try to handle the intent as a media button event wrapped by MediaButtonReceiver
      MediaButtonReceiver.handleIntent(session, startIntent);
    }
  }
  // Reset the delay handler to enqueue a message to stop the service if nothing is playing
  delayedStopHandler.removeCallbacksAndMessages(null);
  delayedStopHandler.sendEmptyMessageDelayed(0, STOP_DELAY);
  return START_STICKY;
}
 
Example #12
Source File: NotificationBuilder.java    From YouTube-In-Background with MIT License 5 votes vote down vote up
public NotificationBuilder(Context context)
{
    this.context = context;

    notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    skipToPreviousAction = new Action(
            R.drawable.exo_controls_previous,
            context.getString(R.string.notification_skip_to_previous),
            MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_SKIP_TO_PREVIOUS)
    );
    playAction = new Action(
            R.drawable.exo_controls_play,
            context.getString(R.string.notification_play),
            MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_PLAY)
    );
    pauseAction = new Action(
            R.drawable.exo_controls_pause,
            context.getString(R.string.notification_pause),
            MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_PAUSE)
    );
    skipToNextAction = new Action(
            R.drawable.exo_controls_next,
            context.getString(R.string.notification_skip_to_next),
            MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_SKIP_TO_NEXT)
    );

    stopPendingIntent = MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_STOP);
}
 
Example #13
Source File: MainActivity.java    From lbry-android with MIT License 5 votes vote down vote up
public void initMediaSession() {
    ComponentName mediaButtonReceiver = new ComponentName(getApplicationContext(), MediaButtonReceiver.class);
    mediaSession = new MediaSessionCompat(getApplicationContext(), "LBRYMediaSession", mediaButtonReceiver, null);
    MediaSessionConnector connector = new MediaSessionConnector(mediaSession);
    connector.setPlayer(MainActivity.appPlayer);
    mediaSession.setActive(true);
}
 
Example #14
Source File: ServicePlayMusic.java    From Bop with Apache License 2.0 5 votes vote down vote up
private void initMediaSession() {
    ComponentName mediaButtonReceiver = new ComponentName(getApplicationContext(), MediaButtonReceiver.class);
    mMediaSessionCompat = new MediaSessionCompat(getApplicationContext(), "Tag", mediaButtonReceiver, null);

    mMediaSessionCompat.setCallback(mMediaSessionCallback);
    mMediaSessionCompat.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);

    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setClass(this, MediaButtonReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);
    mMediaSessionCompat.setMediaButtonReceiver(pendingIntent);

    setSessionToken(mMediaSessionCompat.getSessionToken());
}
 
Example #15
Source File: PlayerService.java    From AndroidAudioExample with MIT License 4 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    MediaButtonReceiver.handleIntent(mediaSession, intent);
    return super.onStartCommand(intent, flags, startId);
}
 
Example #16
Source File: PlayerService.java    From AndroidAudioExample with MIT License 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        @SuppressLint("WrongConstant") NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_DEFAULT_CHANNEL_ID, getString(R.string.notification_channel_name), NotificationManagerCompat.IMPORTANCE_DEFAULT);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.createNotificationChannel(notificationChannel);

        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_MEDIA)
                .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                .build();
        audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN)
                .setOnAudioFocusChangeListener(audioFocusChangeListener)
                .setAcceptsDelayedFocusGain(false)
                .setWillPauseWhenDucked(true)
                .setAudioAttributes(audioAttributes)
                .build();
    }

    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    mediaSession = new MediaSessionCompat(this, "PlayerService");
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(mediaSessionCallback);

    Context appContext = getApplicationContext();

    Intent activityIntent = new Intent(appContext, MainActivity.class);
    mediaSession.setSessionActivity(PendingIntent.getActivity(appContext, 0, activityIntent, 0));

    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null, appContext, MediaButtonReceiver.class);
    mediaSession.setMediaButtonReceiver(PendingIntent.getBroadcast(appContext, 0, mediaButtonIntent, 0));

    exoPlayer = ExoPlayerFactory.newSimpleInstance(this, new DefaultRenderersFactory(this), new DefaultTrackSelector(), new DefaultLoadControl());
    exoPlayer.addListener(exoPlayerListener);
    DataSource.Factory httpDataSourceFactory = new OkHttpDataSourceFactory(new OkHttpClient(), Util.getUserAgent(this, getString(R.string.app_name)));
    Cache cache = new SimpleCache(new File(this.getCacheDir().getAbsolutePath() + "/exoplayer"), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 100)); // 100 Mb max
    this.dataSourceFactory = new CacheDataSourceFactory(cache, httpDataSourceFactory, CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR);
    this.extractorsFactory = new DefaultExtractorsFactory();
}
 
Example #17
Source File: VinylCastHelpers.java    From vinyl-cast with MIT License 4 votes vote down vote up
public static void createStopNotification(MediaSessionCompat mediaSession,
                                          Service context,
                                          Class<?> serviceClass,
                                          String NOTIFICATION_CHANNEL_ID,
                                          int NOTIFICATION_ID,
                                          String httpStreamUrl) {
    createNotificationChannel(context, NOTIFICATION_CHANNEL_ID);

    PendingIntent stopIntent = PendingIntent.getService(context, 0, getServiceActionIntent(VinylCastService.ACTION_STOP_RECORDING, context, serviceClass), PendingIntent.FLAG_CANCEL_CURRENT);
    PendingIntent mainActivityIntent = PendingIntent.getActivity(context, 0, getActivityIntent(context, MainActivity.class), 0);

    MediaControllerCompat controller = mediaSession.getController();
    MediaMetadataCompat mediaMetadata = controller.getMetadata();
    MediaDescriptionCompat mediaDescription = mediaMetadata == null ? null : mediaMetadata.getDescription();

    CharSequence contentTitle = mediaDescription == null ? context.getString(R.string.notification_content_title) : mediaDescription.getTitle();
    CharSequence contentText = mediaDescription == null ? httpStreamUrl : mediaDescription.getSubtitle();
    CharSequence subText = mediaDescription == null ? null : mediaDescription.getDescription();
    Bitmap largeIcon = mediaDescription == null ? null : mediaDescription.getIconBitmap();

    // Start foreground service to avoid unexpected kill
    Notification notification = new Builder(context)
            .setChannelId(NOTIFICATION_CHANNEL_ID)
            .setContentTitle(contentTitle)
            .setContentText(contentText)
            .setSubText(subText)
            .setLargeIcon(largeIcon)
            .setContentIntent(mainActivityIntent)
            .setDeleteIntent(stopIntent)
            .setShowWhen(false)
            // Add a pause button
            .addAction(new Action(
                    R.drawable.ic_stop_black_24dp, context.getString(R.string.button_stop),
                    MediaButtonReceiver.buildMediaButtonPendingIntent(context,
                            PlaybackStateCompat.ACTION_STOP)))
            .setStyle(new MediaStyle()
                    .setMediaSession(mediaSession.getSessionToken())
                    .setShowActionsInCompactView(0)
                    .setShowCancelButton(true)
                    .setCancelButtonIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(context,
                            PlaybackStateCompat.ACTION_STOP)))
            .setSmallIcon(R.drawable.ic_record_black_100dp)
            .setVisibility(VISIBILITY_PUBLIC)
            .build();

    context.startForeground(NOTIFICATION_ID, notification);
}
 
Example #18
Source File: BaseWidget.java    From Jockey with Apache License 2.0 4 votes vote down vote up
protected PendingIntent getSkipNextIntent(Context context) {
    return MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_SKIP_TO_NEXT);
}
 
Example #19
Source File: BaseWidget.java    From Jockey with Apache License 2.0 4 votes vote down vote up
protected PendingIntent getSkipPreviousIntent(Context context) {
    return MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_SKIP_TO_PREVIOUS);
}
 
Example #20
Source File: BaseWidget.java    From Jockey with Apache License 2.0 4 votes vote down vote up
protected PendingIntent getPlayPauseIntent(Context context) {
    return MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_PLAY_PAUSE);
}
 
Example #21
Source File: NotificationPanel.java    From flutter_media_notification with MIT License 4 votes vote down vote up
@Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        boolean isPlaying = intent.getBooleanExtra("isPlaying", true);
        String title = intent.getStringExtra("title");
        String author = intent.getStringExtra("author");

        createNotificationChannel();


        MediaSessionCompat mediaSession = new MediaSessionCompat(this, MEDIA_SESSION_TAG);


        int iconPlayPause = R.drawable.baseline_play_arrow_black_48;
        String titlePlayPause = "pause";
        if(isPlaying){
            iconPlayPause=R.drawable.baseline_pause_black_48;
            titlePlayPause="play";
        }

        Intent toggleIntent = new Intent(this, NotificationReturnSlot.class)
                .setAction("toggle")
                .putExtra("title",  title)
                .putExtra("author",  author)
                .putExtra("play", !isPlaying);
        PendingIntent pendingToggleIntent = PendingIntent.getBroadcast(this, 0, toggleIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        MediaButtonReceiver.handleIntent(mediaSession, toggleIntent);

        //TODO(ALI): add media mediaSession Buttons and handle them
        Intent nextIntent = new Intent(this, NotificationReturnSlot.class)
                .setAction("next");
        PendingIntent pendingNextIntent = PendingIntent.getBroadcast(this, 0, nextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//        MediaButtonReceiver.handleIntent(mediaSession, nextIntent);

        Intent prevIntent = new Intent(this, NotificationReturnSlot.class)
                .setAction("prev");
        PendingIntent pendingPrevIntent = PendingIntent.getBroadcast(this, 0, prevIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//        MediaButtonReceiver.handleIntent(mediaSession, prevIntent);

        Intent selectIntent = new Intent(this, NotificationReturnSlot.class)
                .setAction("select");
        PendingIntent selectPendingIntent = PendingIntent.getBroadcast(this, 0, selectIntent, PendingIntent.FLAG_CANCEL_CURRENT);
//        MediaButtonReceiver.handleIntent(mediaSession, selectIntent);

        Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
                .addAction(R.drawable.baseline_skip_previous_black_48, "prev", pendingPrevIntent)
                .addAction(iconPlayPause, titlePlayPause, pendingToggleIntent)
                .addAction(R.drawable.baseline_skip_next_black_48, "next", pendingNextIntent)
                .setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
                        .setShowActionsInCompactView(0, 1,2)
                        .setShowCancelButton(true)
                        .setMediaSession(mediaSession.getSessionToken()))
                .setSmallIcon(R.drawable.ic_stat_music_note)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setVibrate(new long[]{0L})
                .setPriority(NotificationCompat.PRIORITY_MAX)
                .setContentTitle(title)
                .setContentText(author)
                .setSubText(title)
                .setContentIntent(selectPendingIntent)
                .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_stat_music_note))
                .build();

        startForeground(NOTIFICATION_ID, notification);
        if(!isPlaying) {
            stopForeground(false);
        }

        return START_NOT_STICKY;
    }
 
Example #22
Source File: TtsService.java    From android-app with GNU General Public License v3.0 4 votes vote down vote up
private PendingIntent generateActionIntent(long action) {
    return MediaButtonReceiver.buildMediaButtonPendingIntent(
            getApplicationContext(), mediaActionComponentName, action);
}