1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.mediarouter.player; 18 19 import android.content.BroadcastReceiver; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.view.KeyEvent; 23 24 /** 25 * Broadcast receiver for handling ACTION_MEDIA_BUTTON. 26 * 27 * This is needed to create the RemoteControlClient for controlling 28 * remote route volume in lock screen. It routes media key events back 29 * to main app activity MainActivity. 30 */ 31 public class SampleMediaButtonReceiver extends BroadcastReceiver { 32 private static final String TAG = "SampleMediaButtonReceiver"; 33 private static MainActivity mActivity; 34 35 public static void setActivity(MainActivity activity) { 36 mActivity = activity; 37 } 38 39 @Override 40 public void onReceive(Context context, Intent intent) { 41 if (mActivity != null && Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) { 42 mActivity.handleMediaKey( 43 (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT)); 44 } 45 } 46 }