admin管理员组文章数量:1548500
我用这个project来模拟android模拟器上的蓝牙.
我有2个类,一个启用蓝牙
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
BluetoothAdapter.SetContext(this);
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if(adapter==null) {
System.out.println("\nBluetooth NOT supported. Aborting.");
return;
}
if (!adapter.isEnabled()) {
adapter.enable();
}
}
另一次扫描设备并列出它们
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
BluetoothAdapter.SetContext(this);
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
System.out.println("\nAdapter: " + adapter);
if(adapter==null) {
System.out.println("\nBluetooth NOT supported. Aborting.");
return;
}
if (!adapter.isEnabled()) {
adapter.enable();
}
if (adapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
adapter.startDiscovery();
}
Set
第二个设备没有检测到任何设备,所以我的代码出了什么问题?
提前致谢.
版权声明:本文标题:android 模拟蓝牙,如何在Android模拟器上模拟蓝牙 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1727207529a1102384.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论