Android examples for android.provider:MediaStore
Create a PendingIntent appropriate for a MediaStyle notification's action.
import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.support.v4.media.MediaDescriptionCompat; import android.support.v4.media.MediaMetadataCompat; import android.support.v4.media.session.MediaControllerCompat; import android.support.v4.media.session.MediaSessionCompat; import android.support.v7.app.NotificationCompat; import android.view.KeyEvent; public class Main{ /**/*w ww .ja v a2s . co m*/ * Create a {@link PendingIntent} appropriate for a MediaStyle notification's action. Assumes * you are using a media button receiver. * @param context Context used to contruct the pending intent. * @param mediaKeyEvent KeyEvent code to send to your media button receiver. * @return An appropriate pending intent for sending a media button to your media button * receiver. */ public static PendingIntent getActionIntent(Context context, int mediaKeyEvent) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setPackage(context.getPackageName()); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent( KeyEvent.ACTION_DOWN, mediaKeyEvent)); return PendingIntent .getBroadcast(context, mediaKeyEvent, intent, 0); } }