Skip to Content
Android 9 Development Cookbook - Third Edition
book

Android 9 Development Cookbook - Third Edition

by Rick Boyer
October 2018
Intermediate to advanced
464 pages
15h 17m
English
Packt Publishing
Content preview from Android 9 Development Cookbook - Third Edition

How it works...

There are four steps to setting this up:

  1. Create a MediaSession.Callback and attach it to MediaSession
  2. Set the MediaSession flags to indicate we want media buttons
  3. Set SessionState to active
  4. Set PlayBackState with the actions we're going to handle

Steps 4 and 1 work together as the callback will only get the events set in the PlayBackState.

Since we're not actually controlling any playback in this recipe, we just demonstrate how to respond to the hardware events. You'll want to implement actual functionality in PlayBackState and include a call to setState() after the setActions() call.

This is a very nice example of how the changes to the API can make things easier. And since the new MediaSession and PlaybackState were rolled ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Android Application Development Cookbook - Second Edition

Android Application Development Cookbook - Second Edition

Rick Boyer, Kyle Mew
Android High Performance Programming

Android High Performance Programming

Enrique López Mañas, Diego Grancini
Android Things Projects

Android Things Projects

Francesco Azzola

Publisher Resources

ISBN: 9781788991216Supplemental Content