1

一段时间以来,我一直在使用接收器来监控这些意图,以监控活动的蓝牙连接。我现在发现在运行 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;
        }
    }
}
4

1 回答 1

5

android:enabled="true"问题是,您必须 android:exported="false"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> 

将其更改为:

<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> 
于 2014-06-20T11:17:19.773 回答