Android 模拟器上的低功耗蓝牙
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20348743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bluetooth Low Energy on Android Emulator
提问by gaborous
I studied about Bluetooth Low Energy.
我研究了蓝牙低功耗。
But I don't have supported BLE device for testing.
但我没有支持 BLE 设备进行测试。
Therefore, I want to ask :
因此,我想问:
Do the Android emulator supports BLE feature for testing?
Android 模拟器是否支持 BLE 功能进行测试?
I tried with the following code on Android Emulator 4.3 (x86) and Android Emulator 4.4 (ARM):
我在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();
}
And it always show "ble_not_supported".
它总是显示 "ble_not_supported"。
Another question is
另一个问题是
Which another emulator or tool supports BLE for Android?
哪个模拟器或工具支持 Android BLE?
I really want to test BLE feature on Emulator.
我真的很想在模拟器上测试 BLE 功能。
采纳答案by Huy Tower
Using the Emulatorsaid that
Emulator Limitations
The functional limitations of the emulator include:
No support for placing or receiving actual phone calls. You can simulate phone calls (placed and received) through the emulator console, however.
No support for USB connections
No support for device-attached headphones
No support for determining network connected state
No support for determining battery charge level and AC charging state
No support for determining SD card insert/eject
No support for Bluetooth
模拟器限制
模拟器的功能限制包括:
不支持拨打或接听实际电话。但是,您可以通过模拟器控制台模拟电话呼叫(拨打和接听)。
不支持 USB 连接
不支持设备连接的耳机
不支持确定网络连接状态
不支持确定电池充电水平和交流充电状态
不支持确定 SD 卡插入/弹出
不支持蓝牙
Thanks,
谢谢,
回答by gaborous
It seems you can, using Android inside a VirtualBox and using a PC dongle supporting Bluetooth LE (costs about 18$ on Amazon). Here's the tutorial by Chris Larson(copied here to keep it online):
似乎可以,在 VirtualBox 中使用 Android 并使用支持蓝牙 LE 的 PC 加密狗(在亚马逊上的成本约为 18 美元)。这是Chris Larson的教程(复制到此处以使其在线):
Android emulators are great for developing BluetoothLE applications. The trick is getting the Android emulator to recognize the BluetoothLE adapter.
What you'll need:
- Androidx86 iso from android-x86.org I used the 4.4 release candidate
- Virtual Machine software: I used Oracle VirtualBox
- A BluetoothLE USB adapter: I used the Cirago Bluetooth 4.0 USB Mini Adapter (BTA8000)(affilate link) or Cirago Bluetooth 4.0 USB Mini Adapter (BTA8000) (non-affilate link)
- Install Android SDK for debugging
- Install VirtualBox
- Download Androidx86
- Open VirtualBox and create a new machine. Set type to linux/other(32bit)
- Set the virtual machine's memory and harddrive space to whatever you need (but at least the minimum specs for Android).
- When asked for the OS image, select the Androidx86 image you download from Androidx86.org
- When the virtual machine boots, choose to install Android.
- When the installation completes, shutdown the Android virtual machine and unmount the iso image
- Plug in the Bluetooth USB adapter and add it to the Android Virtual Machine's settings
- Start the Android Virtual Machine and go through the start-up screens to configure Android for use
- In the Android VM go to the settings and enable BluetoothLE (if this fails reboot the VM and try to enable again)
Android 模拟器非常适合开发 BluetoothLE 应用程序。诀窍是让 Android 模拟器识别 BluetoothLE 适配器。
你需要什么:
- 来自 android-x86.org 的 Androidx86 iso 我使用了 4.4 候选版本
- 虚拟机软件:我用的是 Oracle VirtualBox
- BluetoothLE USB 适配器:我使用了 Cirago 蓝牙 4.0 USB 迷你适配器 (BTA8000)(附属链接)或 Cirago 蓝牙 4.0 USB 迷你适配器(BTA8000)(非附属链接)
- 安装 Android SDK 进行调试
- 安装 VirtualBox
- 下载 Androidx86
- 打开 VirtualBox 并创建一台新机器。设置类型为 linux/other(32bit)
- 将虚拟机的内存和硬盘空间设置为您需要的任何内容(但至少是 Android 的最低规格)。
- 当要求提供操作系统映像时,选择您从 Androidx86.org 下载的 Androidx86 映像
- 虚拟机启动时,选择安装Android。
- 安装完成后,关闭Android虚拟机并卸载iso镜像
- 插入蓝牙USB适配器并将其添加到Android虚拟机的设置中
- 启动 Android 虚拟机并通过启动屏幕配置 Android 以供使用
- 在 Android VM 中,转到设置并启用 BluetoothLE(如果失败,请重新启动 VM 并再次尝试启用)
Here are a few other links describing more or less the same method, and a few other tools that can be of interest to you:
这里有一些其他链接或多或少描述了相同的方法,以及您可能感兴趣的其他一些工具:
- http://technoga.wordpress.com/2013/05/06/debug-a-bluetooth-app-with-android-emulator-on-pc/
- http://niro-offonatangent.blogspot.fr/2011/06/bluetooth-support-on-android-emulator.html
- http://referenceforu.blogspot.fr/2013/08/testing-bluetooth-in-android-emulator.html
- https://stackoverflow.com/a/2614840/1121352
- https://github.com/cheng81/Android-Bluetooth-Simulator
- https://play.google.com/store/apps/details?id=com.magicandroidapps.bluetoothterm&hl=fr
- a set of opensource tools to develop Bluetooth LE apps on Android: https://github.com/grundid/bletoolsand http://blog.opendatalab.de/hack/2013/11/15/bluetooth-low-energy-tools-library-for-android/
- http://technoga.wordpress.com/2013/05/06/debug-a-bluetooth-app-with-android-emulator-on-pc/
- http://niro-offonatangent.blogspot.fr/2011/06/bluetooth-support-on-android-emulator.html
- http://referenceforu.blogspot.fr/2013/08/testing-bluetooth-in-android-emulator.html
- https://stackoverflow.com/a/2614840/1121352
- https://github.com/cheng81/Android-Bluetooth-Simulator
- https://play.google.com/store/apps/details?id=com.magicandroidapps.bluetoothterm&hl=fr
- 一组用于在 Android 上开发蓝牙 LE 应用程序的开源工具:https: //github.com/grundid/bletools和http://blog.opendatalab.de/hack/2013/11/15/bluetooth-low-energy-tools - 安卓库/
And if you want this issue to be solved by Google, you can star this thread to make it more visible (with enough votes, Google will tackle it in a few years, as they did with audio issues...):
如果你希望谷歌解决这个问题,你可以给这个帖子加注星标,让它更显眼(如果有足够的投票,谷歌将在几年内解决它,就像他们处理音频问题一样......):