0

しばらく探しましたが、方法がないようです。しかし..

Bluetooth デバイスの接続状態のインテント フィルターはありますか? 使ってみました。BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGEDしかし、それは決して受け取られません。はい、インテント フィルターを登録します。

logcat では、BluetoothService Making callback for "UUID" が表示され、デバイスが接続された直後に結果が 1 になりますが、何も受信されませんでした

4

1 に答える 1

0

以下を試してください、

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.os.Bundle;
import android.widget.Toast;

public class BluetoothStatus extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();

  String toastText;
  if (bluetooth.isEnabled()) {
   String address = bluetooth.getAddress();
   String name = bluetooth.getName();
   toastText = name + " : " + address;
  } else
   toastText = "Bluetooth is not enabled";

  Toast.makeText(this, toastText, Toast.LENGTH_LONG).show();

  bluetooth.setName("Enrichware");

 }
}

詳細: http://learnandroiddevelopment.blogspot.in/2011/02/android-how-to-find-bluetooth-status.html

IntentFilter の使用、サンプル: Bluetooth デバイスが接続されているかどうかをプログラムで確認する方法は? (アンドロイド2.2)

于 2012-06-26T05:04:29.043 に答える