BootBroadcastReceiver.java
2015-11-28 11:26
405 查看
与A2dpSinkAvrcpService.java在同一个文件下编译
package com.android.a2dpsink;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.bluetooth.BluetoothA2dpSink;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothAdapter;
public class BootBroadcastReceiver extends BroadcastReceiver {
private static int NEXT_STATE = 1;
private static final String TAG = "BootBroadcastReceiver";
//蓝牙适配器开启就startservice
static final String ACTION = "android.bluetooth.adapter.action.STATE_CHANGED";
//static final String ACTION = "android.bluetooth.a2dp-sink.profile.action.CONNECTION_STATE_CHANGED";
//接收这个自定义广播就stopservice
static final String STOP = "BootBroadcastReceiver.javareceiver";
public void onReceive(Context context, Intent intent) {
Intent bIntent = new Intent(context,A2dpSinkAvrcpService.class);
if (intent.getAction().equals(ACTION)){
/* int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE,NEXT_STATE);
if (1 == state) {
context.startService(bIntent);
Log.d(TAG, "startService...");
}
*/
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
if (BluetoothAdapter.STATE_ON == state) {
context.startService(bIntent);
Log.d(TAG, "startService...");
}
}
if (intent.getAction().equals(STOP)){
context.stopService(bIntent);
Log.d(TAG,"stopService...");
}
}
}
package com.android.a2dpsink;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.bluetooth.BluetoothA2dpSink;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothAdapter;
public class BootBroadcastReceiver extends BroadcastReceiver {
private static int NEXT_STATE = 1;
private static final String TAG = "BootBroadcastReceiver";
//蓝牙适配器开启就startservice
static final String ACTION = "android.bluetooth.adapter.action.STATE_CHANGED";
//static final String ACTION = "android.bluetooth.a2dp-sink.profile.action.CONNECTION_STATE_CHANGED";
//接收这个自定义广播就stopservice
static final String STOP = "BootBroadcastReceiver.javareceiver";
public void onReceive(Context context, Intent intent) {
Intent bIntent = new Intent(context,A2dpSinkAvrcpService.class);
if (intent.getAction().equals(ACTION)){
/* int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE,NEXT_STATE);
if (1 == state) {
context.startService(bIntent);
Log.d(TAG, "startService...");
}
*/
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
if (BluetoothAdapter.STATE_ON == state) {
context.startService(bIntent);
Log.d(TAG, "startService...");
}
}
if (intent.getAction().equals(STOP)){
context.stopService(bIntent);
Log.d(TAG,"stopService...");
}
}
}
相关文章推荐
- 蓝牙天线的一点小资料
- Core Bluetooth for iOS 6
- rtl8723bs移植之打开wifi后系统不断重启
- Ubuntu和Windows双系统蓝牙键盘配对
- A2dpSinkAvrcpService.java
- Android BLE教程(和单片机通信)
- android Bluetooth连接方式 SCO & ACL
- 一、Bluetooth Native层与协议栈的接口及其初始化过程
- 蓝牙串口通信
- Android-BLE 2. 蓝牙的权限使用
- Android-BLE 1. 基本类的介绍
- 完美解决iphone连电脑蓝牙出现bluetooth外围设备无法正确安装
- 关于Rayeager PX2开发板 Bluetooth不能使用的解决
- 蓝牙音频音质探讨
- 如何理解蓝牙芯片内部逻辑
- 蓝牙物理连接的建立
- Android 4.2蓝牙介绍
- TI低功耗蓝牙(BLE)介绍
- 蓝牙绕过系统Pin弹窗自动匹配,亲测4.0以上没问题
- 关于: 安卓能否与iphone通过蓝牙4.0(BLE)通讯?