简体   繁体   English

蓝牙连接状态

[英]Bluetooth connection state

I've been searching for a while and there doesn't seem to be a way. 我搜索了一段时间,似乎没有办法。 But.. 但..

Is there any intent filter for the connection state of a bluetooth device? 蓝牙设备的连接状态是否有任何意图过滤器? I tried using. 我尝试使用。 BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED but that is never recieved. BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED但从未收到。 Yes I do register the intent filter. 是的,我确实注册了意图过滤器。

In logcat I see BluetoothService Making callback for "UUID" with result 1 right after the device is connected but nothing os received 在logcat中,我在连接设备后立即看到BluetoothService正在对“ UUID”进行回调,结果为1,但未收到任何操作系统

Try the below, 试试下面的,

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");

 }
}

Details: http://learnandroiddevelopment.blogspot.in/2011/02/android-how-to-find-bluetooth-status.html 详细信息: http : //learnandroiddevelopment.blogspot.in/2011/02/android-how-to-find-bluetooth-status.html

Using IntentFilter, Sample: How to programmatically tell if a Bluetooth device is connected? 使用IntentFilter,示例: 如何以编程方式判断是否已连接蓝牙设备? (Android 2.2) (Android 2.2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当蓝牙连接状态改变时防止 onDestroy - Prevent onDestroy when Bluetooth connection state changes 如何以编程方式检查Android中蓝牙设备的连接状态? - How to programmatically check connection state of a Bluetooth device in Android? 如何在Android中检查配对设备的蓝牙连接状态 - How to check bluetooth connection state with paired device in Android Android蓝牙:动态更新列表视图中单行的连接状态 - Android Bluetooth: Update connection state dynamically for single row in listview 蓝牙连接 - Bluetooth Connection 从Android中的一项活动转移到另一项活动后,如何保持蓝牙低功耗设备的连接状态? - How to persist the Bluetooth Low Energy Device connection state after passing from one activity to another in Android? 当应用程序在后台运行且没有前台服务时如何检测蓝牙变化(连接状态和特性) - How to detect bluetooth changes (connection state and characteristic) when app is in background without a foreground service 是否对蓝牙RFCOMM / SPP连接的更改广播了ACTION_CONNECTION_STATE_CHANGED? - Is ACTION_CONNECTION_STATE_CHANGED broadcasted on changes to Bluetooth RFCOMM / SPP connections? 如何使用Android2.2在应用程序启动时获得蓝牙耳机连接状态? - How to get Bluetooth Headset connection state on application start-up using Android2.2? 蓝牙ToggleButton不检查状态 - Bluetooth ToggleButton not checking state
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM