1

Bluetooth 接続/切断イベントをリッスンして、Bluetooth デバイスが接続されているかどうかを判断しようとしています。私のアプリが古いAndroidバージョンで実行されるように、このようにしようとしています。

マニフェストにレシーバーを次のように登録しました。

<receiver
        android:name=".BluetoothReceiver">
        <intent-filter>
            <action android:name="android.bluetooth.device.action.ACL_CONNECTED" />

        </intent-filter>
</receiver>

そして、私の BluetoothReceiver クラスには

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());
    }
}}

しかし、ブルートゥースに接続したり切断したりしても、何も起こりません。私は何を間違っていますか?

4

0 に答える 0