Android 如何判断蓝牙设备是否已连接?我的代码不是';行不通
我正在尝试侦听蓝牙连接/断开事件,以确定是否连接了蓝牙设备。我正试图这样做,这样我的应用程序就可以在旧的android版本上运行 我在舱单中登记了接收人:Android 如何判断蓝牙设备是否已连接?我的代码不是';行不通,android,android-intent,Android,Android Intent,我正在尝试侦听蓝牙连接/断开事件,以确定是否连接了蓝牙设备。我正试图这样做,这样我的应用程序就可以在旧的android版本上运行 我在舱单中登记了接收人: <receiver android:name=".BluetoothReceiver"> <intent-filter> <action android:name="android.bluetooth.device.action.ACL_CONNECTED"
<receiver
android:name=".BluetoothReceiver">
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
</intent-filter>
</receiver>
但当连接和断开蓝牙时,什么也不会发生。我做错了什么?如果是蓝牙耳机,请参阅
public class BluetoothReceiver extends BroadcastReceiver{
public final static String TAG = "BluetoothReciever";
public void onReceive(Context context, Intent intent)
{
Log.d(TAG, "Bluetooth Intent Recieved");
final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String action = intent.getAction();
if (BluetoothDevice.ACTION_ACL_CONNECTED.equalsIgnoreCase(action))
{
Log.d(TAG, "Connected to " + device.getName());
}
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equalsIgnoreCase(action))
{
Log.d(TAG, "Disconnected from " + device.getName());
}
}}