
我用这个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第二个设备没有检测到任何设备,所以我的代码出了什么问题?
提前致谢.最佳答案BluetoothAdapter.getDefaultAdapter()返回默认的本地适配器.
如果设备没有蓝牙功能,它将返回null,并且由于您使用的是不支持蓝牙的仿真器,它将返回null. 总结
以上是内存溢出为你收集整理的如何在Android模拟器上模拟蓝牙全部内容,希望文章能够帮你解决如何在Android模拟器上模拟蓝牙所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)