如何在 Android 模拟器中使用蓝牙?

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

How to use Bluetooth in Android emulator?

android

提问by Rajapandian

I want to create an application based on bluetooth operation in android.I am using the following code

我想在android中创建一个基于蓝牙操作的应用程序。我正在使用以下代码

 BluetoothAdapter adapter=BluetoothAdapter.getDefaultAdapter();

the adapter is returning null value, which means the android emulator is not having bluetooth capability. i am using android 2.1 the latest version of android.Anybody knows how to use the bluetooth from android emulator, please help me.

适配器返回空值,这意味着 android 模拟器没有蓝牙功能。我正在使用 android 2.1 最新版本的 android.Anybody 知道如何使用来自 android 模拟器的蓝牙,请帮助我。

回答by MrSnowflake

You can't. The emulator does not support Bluetooth, as mentioned in the SDK's docs and on several other places.

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

And you already discovered this yourself: "the adapter is returning null value, which means the android emulator is not having bluetooth capability"

而且您自己已经发现了这一点:“适配器返回空值,这意味着 android 模拟器没有蓝牙功能”

回答by drott

You can install the image from http://www.android-x86.org/into a virtual machine (e.g. VMWare), find out it's IP address, connect manually using

您可以将http://www.android-x86.org/ 中的镜像安装 到虚拟机(例如 VMWare)中,找出它的 IP 地址,使用手动连接

adb connect <IP of VM>

And then launch your project from Eclipse by setting a "Manual" deployment target in your Debug/Run configuration. Bluetooth works in this Virtual Machine at least on my Macbook and it's reported to work with a couple of other bluetooth chipsets.

然后通过在调试/运行配置中设置“手动”部署目标,从 Eclipse 启动您的项目。蓝牙至少在我的 Macbook 上可以在这个虚拟机中使用,据报道它可以与其他几个蓝牙芯片组一起使用。

回答by Martin

I'm currently planning a tool that is capable of emulating Bluetooth over TCP/IP under Linux (will be released freely under GPL).

我目前正在计划一种能够在 Linux 下通过 TCP/IP 模拟蓝牙的工具(将在 GPL 下免费发布)。

This should be the solution when not having a real Bluetooth device (e.g. you want to simulate a connection between two emulated Android-x86 or Linux machines).

当没有真正的蓝牙设备时,这应该是解决方案(例如,您想模拟两台模拟的 Android-x86 或 Linux 机器之间的连接)。

Maybe when compiling for Linux-ARM instead of Linux-x86 it will run in the Emulator, too.

也许在为 Linux-ARM 而不是 Linux-x86 编译时,它也会在模拟器中运行。

回答by Zeegmo

It's not possible to run bluetooth aap on emulator.as there is no support for bluetooth on emulator. look at this http://developer.android.com/guide/developing/devices/emulator.htmlEmulator Limitations

无法在模拟器上运行蓝牙 aap。因为模拟器不支持蓝牙。看看这个http://developer.android.com/guide/developing/devices/emulator.html模拟器限制

In this release, the 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 camera/video capture (input).
  • No support for device-attached headphones
  • No support for determining 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 卡插入/弹出
  • 不支持蓝牙

回答by Hunt

Q. Bluetooth doesn't work on my device. How should I debug?

问。 Bluetooth doesn't work on my device. How should I debug?

A. First step - read the logs (adb logcat)! In particular look for ERROR or WARNING level messages regarding Bluetooth.

A. 第一步 - 阅读日志 ( adb logcat)!尤其要查找有关蓝牙的错误或警告级别消息。

Andtheitroadd uses Bluez, which comes with some very useful debugging tools. Here are some examples, in the rough order I use to debug BT.

Andtheitroadd 使用 Bluez,它带有一些非常有用的调试工具。以下是一些示例,按照我用来调试 BT 的粗略顺序。

hciconfig -a  # print BT chipset address and features. Useful to
# check if you can communicate with your BT chipset.

hcidump -XVt  # print live HCI UART traffic.
hcitool scan  # scan for local devices. Useful to check if RX/TX works.
l2ping ADDRESS  # ping another BT device. Useful to check if RX/TX works.
sdptool records ADDRESS # request the SDP records of another BT device.

You can install the bluetooth plugin from http://www.android-videos.blogspot.com/Once the installation is done you can use bluetooth with the Emulator.

您可以从http://www.android-videos.blogspot.com/安装蓝牙插件安装完成后,您可以在模拟器上使用蓝牙。

回答by vivek satasia

Yes, I agree, right now the emulator does not support Bluetooth.

是的,我同意,现在模拟器不支持蓝牙。

To compile Android with Bluetooth support enabled, add the following line to BoardConfig.mk.

要在启用蓝牙支持的情况下编译 Android,请将以下行添加到BoardConfig.mk.

BOARD_HAVE_BLUETOOTH := true

回答by gaborous

You can but you will need to run your app on an Android inside a VirtualBox or VMWare image. For more infos, see here (tutorial is for Bluetooth LE, but it works just the same with other Bluetooth versions): Bluetooth Low Energy on Android Emulator

您可以,但您需要在 VirtualBox 或 VMWare 映像内的 Android 上运行您的应用程序。有关更多信息,请参阅此处(教程适用于蓝牙 LE,但它与其他蓝牙版本的工作原理相同):Android Emulator 上的低功耗蓝牙

回答by sagar.android

The emulator doesnt support bluetooth as mentioned in the sdk's docs. You have to check this in real device..

模拟器不支持 sdk 文档中提到的蓝牙。你必须在真实设备中检查这个..

And you got error Bluetooth binder is null. it means emulator does not have bluetooth capability.

你得到错误蓝牙活页夹为空。这意味着模拟器没有蓝牙功能。