我一直在使用接收器来监控这些意图一段时间,以监控有效的蓝牙连接。我现在发现在运行android 4.2.2的Galaxy S4上,这些意图似乎根本没有。
它适用于我的Transformer Infinity(4.1),Droid Bionic(4.1)和Droid X(2.3.3)。在4.2.2中有什么改变打破了这种方法吗?
以下是我的代码供参考。
public class BluetoothReceiver extends BroadcastReceiver
{
public static boolean BluetoothConnected;
public void onReceive(Context context, Intent intent)
{
Log.d(TAG, "Bluetooth Intent Recieved");
String action = intent.getAction();
Log.d(TAG, "Bluetooth Called: Action: " + action);
if (action.equalsIgnoreCase("android.bluetooth.device.action.ACL_CONNECTED"))
{
Log.d(TAG, "BLUETOOTH CONNECTED RECIEVED");
BluetoothConnected = true;
}
if (action.equalsIgnoreCase("android.bluetooth.device.action.ACL_DISCONNECTED"))
{
Log.d(TAG, "BLUETOOTH DISCONNECTED RECIEVED");
BluetoothConnected = false;
}
}
}
答案 0 :(得分:0)
问题是,您必须从 BroadcastReceiver 中删除这些android:enabled="true"
和android:exported="false"
。
<receiver android:name="com.example.BluetoothReceiver "
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED"/>
</intent-filter>
</receiver>
将此更改为:
<receiver android:name="com.example.BluetoothReceiver">
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED"/>
</intent-filter>
</receiver>