如何使用android模拟器测试蓝牙应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22604305/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:14:11  来源:igfitidea点击:

How to use android emulator for testing bluetooth application?

android

提问by Usman Khan

I am developing an application which will send a request to a bluetooth printer for printing. The code is working fine for real devices, but I want to run it on the Android Emulator. How can I use the emulator for bluetooth testing?

我正在开发一个应用程序,它将向蓝牙打印机发送请求以进行打印。该代码在真实设备上运行良好,但我想在 Android 模拟器上运行它。如何使用模拟器进行蓝牙测试?

回答by Lokesh

You can't. The emulator does not support Bluetooth, as mentioned in the SDK's docs and several other places. Android emulator does not have bluetooth capabilities".

你不能。模拟器不支持蓝牙,如 SDK 文档和其他几个地方所述。Android 模拟器没有蓝牙功能”。

You can only use real devices.

您只能使用真实设备。

Emulator Limitations

模拟器限制

The functional limitations of the emulator include:

模拟器的功能限制包括:

  • No support for placing or receiving actual phone calls. However, You can simulate phone calls (placed and received) through the emulator console
  • No support for USB
  • No support for device-attached headphones
  • No support for determining SD card insert/eject
  • No support for WiFi, Bluetooth, NFC
  • 不支持拨打或接听实际电话。但是,您可以通过模拟器控制台模拟电话(拨打和接听)
  • 不支持USB
  • 不支持设备连接的耳机
  • 不支持确定 SD 卡插入/弹出
  • 不支持 WiFi、蓝牙、NFC

Refer to the documentation

参考文档

回答by Sree

Download Androidx86 from thisThis is an iso file, so you'd
need something like VMWare or VirtualBox to run it When creating the virtual machine, you need to set the type of guest OS as Linux instead of Other.

这里下载Androidx86这是一个iso文件,所以你
需要像VMWare或VirtualBox之类的东西来运行它在创建虚拟机时,你需要将guest OS的类型设置为Linux而不是Other。

After creating the virtual machine set the network adapter to 'Bridged'. · Start the VM and select 'Live CD VESA' at boot.

创建虚拟机后,将网络适配器设置为“桥接”。· 启动虚拟机并在启动时选择“Live CD VESA”。

Now you need to find out the IP of this VM. Go to terminal in VM (use Alt+F1 & Alt+F7 to toggle) and use the netcfg command to find this.

现在你需要找出这个虚拟机的 IP。转到 VM 中的终端(使用 Alt+F1 和 Alt+F7 切换)并使用 netcfg 命令找到它。

Now you need open a command prompt and go to your android install folder (on host). This is usually C:\Program Files\Android\android-sdk\platform-tools>.

现在您需要打开命令提示符并转到您的 android 安装文件夹(在主机上)。这通常是 C:\Program Files\Android\android-sdk\platform-tools>。

Type adb connect IP_ADDRESS. There done! Now you need to add Bluetooth. Plug in your USB Bluetooth dongle/Bluetooth device.

输入 adb connect IP_ADDRESS。完成了!现在您需要添加蓝牙。插入您的 USB 蓝牙加密狗/蓝牙设备。

In VirtualBox screen, go to Devices>USB devices. Select your dongle.

在 VirtualBox 屏幕中,转到设备>USB 设备。选择您的加密狗。

Done! now your Android VM has Bluetooth. Try powering on Bluetooth and discovering/paring with other devices.

完毕!现在你的安卓虚拟机有蓝牙了。尝试打开蓝牙并发现/与其他设备配对。

Now all that remains is to go to Eclipse and run your program. The Android AVD manager should show the VM as a device on the list.

现在剩下的就是转到 Eclipse 并运行您的程序。Android AVD 管理器应将 VM 显示为列表中的设备。

Alternatively, Under settings of the virtual machine, Goto serialports -> Port 1 check Enable serial port select a port number then select port mode as disconnected click ok. now, start virtual machine. Under Devices -> USB Devices -> you can find your laptop bluetooth listed. You can simply check the option and start testing the android bluetooth application .

或者,在虚拟机的设置下,转到串行端口-> 端口 1 选中启用串行端口选择一个端口号,然后选择端口模式为断开连接单击确定。现在,启动虚拟机。在设备 -> USB 设备 -> 下,您可以找到列出的笔记本电脑蓝牙。您可以简单地选中该选项并开始测试 android 蓝牙应用程序。

Source

来源