我正在开发一个应用程序,它将向蓝牙打印机发送请求以进行打印.代码适用于真实设备,但我想在Android模拟器上运行它.如何使用模拟器进行蓝牙测试?
我研究了蓝牙低功耗.
但我没有支持BLE设备进行测试.
因此,我想问:
Android模拟器是否支持BLE功能进行测试?
我在Android Emulator 4.3(x86)和Android Emulator 4.4(ARM)上尝试使用以下代码:
// Use this check to determine whether BLE is supported on the device. Then
// you can selectively disable BLE-related features.
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
finish();
}
Run Code Online (Sandbox Code Playgroud)
它总是显示"ble_not_supported".
另一个问题是
哪个其他模拟器或工具支持Android的BLE?
我真的想在模拟器上测试BLE功能.
android bluetooth emulation android-emulator bluetooth-lowenergy
我试图启用禁用蓝牙设备。因此,我在下面编写了代码,但给出了错误,该错误也在下面。
if ( bluetoothAdmin == null ) {
return ;
}
if ( bluetooth . isEnabled()){
bluetooth . disable ();
}
else {
bluetooth . enable();
}
Run Code Online (Sandbox Code Playgroud)
在创建
BLuetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter() ;
Run Code Online (Sandbox Code Playgroud)
在清单上
<uses-permission
android:name="android.permission.BLUETOOTH"
/>
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN"
/>
Run Code Online (Sandbox Code Playgroud)
错误:
01-23 07:18:53.167: E/BluetoothAdapter(883): Bluetooth binder is null
Run Code Online (Sandbox Code Playgroud)
一半的堆栈:
01-23 07:36:55.624: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
01-23 07:37:16.954: E/ActivityThread(642): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d51230 that was originally bound here
01-23 07:37:16.954: E/ActivityThread(642): …Run Code Online (Sandbox Code Playgroud)