Reputation: 85
I've been using a receiver to monitor those intents for a while now to monitor an active bluetooth connection. I've found now that on my Galaxy S4 running android 4.2.2, these intents do not seem to take at all.
It works on my Transformer Infinity(4.1), Droid Bionic(4.1), and Droid X(2.3.3). Was something changed in 4.2.2 that breaks this method?
Heres my code for reference.
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;
}
}
}
Upvotes: 1
Views: 7265
Reputation: 5152
the issue is, you have to remove these android:enabled="true"
and android:exported="false"
from your BroadcastReceiver.
<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>
change this into this:
<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>
Upvotes: 5