Docs: Used NotificationCompat.MediaStyle

In the Controlling Media section, updated the overview and sample code to
reference NotificationCompat.MediaStyle. Removed the note about the
pre-requisite to have Android 5.0 and higher.

Bug: 22505224
Change-Id: Id9a647ca8eec7f1b763227ee4fd1f18dee4bcb6f
This commit is contained in:
Hemal Patel
2016-07-22 15:50:48 -07:00
parent 0b80531b5b
commit d3c609cbc1

View File

@@ -886,35 +886,38 @@ method.</p>
<h3 id="controllingMedia">Controlling Media Playback on the Lock Screen</h3> <h3 id="controllingMedia">Controlling Media Playback on the Lock Screen</h3>
<p>In Android 5.0 (API level 21) the lock screen no longer displays media controls <p>
based on the {@link android.media.RemoteControlClient}, which is now deprecated. Instead, use the In Android 5.0 (API level 21) the lock screen no longer displays media
{@link android.app.Notification.MediaStyle} template with the controls based on the {@link android.media.RemoteControlClient}, which is
{@link android.app.Notification.Builder#addAction(android.app.Notification.Action) addAction()} now deprecated. Instead, use the {@link
method, which converts actions into clickable icons.</p> android.support.v7.app.NotificationCompat.MediaStyle} template with the
{@link
android.support.v4.app.NotificationCompat.Builder#addAction(android.support.v4.app.NotificationCompat.Action)
addAction()} method, which converts actions into clickable icons.
</p>
<p class="note"><strong>Note:</strong> The template and the <p>
{@link android.app.Notification.Builder#addAction(android.app.Notification.Action) addAction()} To display media playback controls on the lock screen in Android 5.0, set
method are not included in the support library, so these features run in Android 5.0 and higher the visibility to {@link
only.</p> android.support.v4.app.NotificationCompat#VISIBILITY_PUBLIC}, as described
above. Then add the actions and set the {@link
<p>To display media playback controls on the lock screen in Android 5.0, set the visibility android.support.v7.app.NotificationCompat.MediaStyle} template, as described
to {@link android.support.v4.app.NotificationCompat#VISIBILITY_PUBLIC}, as described above. Then add in the following sample code:
the actions and set the {@link android.app.Notification.MediaStyle} template, as described in the </p>
following sample code:</p>
<pre> <pre>
Notification notification = new Notification.Builder(context) Notification notification = new NotificationCompat.Builder(context)
// Show controls on lock screen even when user hides sensitive content. // Show controls on lock screen even when user hides sensitive content.
.setVisibility(Notification.VISIBILITY_PUBLIC) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setSmallIcon(R.drawable.ic_stat_player) .setSmallIcon(R.drawable.ic_stat_player)
// Add media control buttons that invoke intents in your media service // Add media control buttons that invoke intents in your media service
.addAction(R.drawable.ic_prev, "Previous", prevPendingIntent) // #0 .addAction(R.drawable.ic_prev, "Previous", prevPendingIntent) // #0
.addAction(R.drawable.ic_pause, "Pause", pausePendingIntent) // #1 .addAction(R.drawable.ic_pause, "Pause", pausePendingIntent) // #1
.addAction(R.drawable.ic_next, "Next", nextPendingIntent) // #2 .addAction(R.drawable.ic_next, "Next", nextPendingIntent) // #2
// Apply the media style template // Apply the media style template
.setStyle(new Notification.MediaStyle() .setStyle(new NotificationCompat.MediaStyle()
.setShowActionsInCompactView(1 /* #1: pause button */) .setShowActionsInCompactView(1 /* #1: pause button */)
.setMediaSession(mMediaSession.getSessionToken()) .setMediaSession(mMediaSession.getSessionToken()))
.setContentTitle("Wonderful music") .setContentTitle("Wonderful music")
.setContentText("My Awesome Band") .setContentText("My Awesome Band")
.setLargeIcon(albumArtBitmap) .setLargeIcon(albumArtBitmap)