[英]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.