Android 接收藍芽耳機按鍵操作
http://blog.chinaunix.net/uid-27875-id-3287837.html
3 | import android.bluetooth.BluetoothAdapter; |
4 | import android.content.BroadcastReceiver; |
5 | import android.content.Context; |
6 | import android.content.Intent; |
7 | import android.view.KeyEvent; |
8 |
9 | public class MediaButtonReceiver extends BroadcastReceiver |
10 | { |
11 | @Override |
12 | public void onReceive(Context context, Intent intent) |
13 | { |
14 | if(intent.getAction().equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) |
15 | ; //此處填寫藍芽斷開或連線時執行的動作 |
16 | else |
17 | {//若上面的程式碼出現問題,則將其遮蔽即可,下列程式碼沒有問題 |
18 | abortBroadcast(); //不知其功能,但不執行或位置不正確會導致下列程式碼失效 |
19 |