如何使用Android2.2在应用程序启动时获取蓝牙耳机连接状态?
如何在应用程序启动时使用 android api level 8 获取蓝牙耳机连接状态(连接/断开连接)? android2.2中有可用的粘性广播意图吗? 有没有API可以获取蓝牙耳机的初始状态? 有没有可用的解决方法?
How to get Bluetooth Headset connection state (connected/disconnected) using android api level 8 on application start-up?
Is there any sticky broadcast intent available in android2.2?
Is there any API to fetch initial Bluetooth Headset state?
Is there any workaround available?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想出了解决方案:
I figured out the solution:
来自packages/apps/Phone/src/com/android/phone/PhoneGlobals.java:1449
from packages/apps/Phone/src/com/android/phone/PhoneGlobals.java:1449
这在应用程序启动时并不会真正起作用,但由于意图过滤器是自动注册的,一旦您的应用程序启动,您可能会拥有一个有效值:
声明以下意图过滤器
并在您的接收器中的 onReceive 检查:
并保存int 作为静态变量。您可以随时访问它,了解 BT 音频是否已连接 (1) / 已断开连接 (0)。不漂亮,但完成了工作。
另请查看:
https://github.com/android/platform_frameworks_base /blob/gingerbread/core/java/android/bluetooth/BluetoothHeadset.java
This won't really work on application startup, but as intent-filters are registered automatically, you might have a valid value, once your app gets started up:
Declare the following intent-filter
and in your Receiver in onReceive check for:
and save the int as a static variable. Access it anytime you want to know if BT audio is connected(1) / disconnected(0). Not pretty, but gets the job done.
Also check out:
https://github.com/android/platform_frameworks_base/blob/gingerbread/core/java/android/bluetooth/BluetoothHeadset.java