想让 Android 蓝牙在应用程序运行之前始终可见吗? [英] Want a Android bluetooth to be always visible until app running?

查看:18
本文介绍了想让 Android 蓝牙在应用程序运行之前始终可见吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的蓝牙在应用程序运行之前可见.就像是无限的时间.用完后我会关掉它.

I want that my bluetooth to be visible until the app is running. Like for infinite time. I will turn it off when Im done with it.

我不希望它像以下方法一样询问用户可见性的持续时间

I don't want it to ask user for duration of visibility as in following method

  Intent discoverableIntent = new
  Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
  discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,300);
  startActivity(discoverableIntent);

请帮忙!

推荐答案

简短的回答是你不能;请参阅此错误报告.相信我,我和你一样对此感到恼火;它使蓝牙上的临时网络变得非常困难.在该线程上有一些建议,即 Honeycomb 中的限制已经消失,并且可能会使其成为 Ice Cream Sandwich.目前没有办法,只能安装自定义 ROM.

The short answer is that you can't; see this bug report. Trust me, I'm as annoyed about this as you are; it makes ad-hoc networking on Bluetooth very difficult. There are some suggestions on that thread that the limitation is gone in Honeycomb and perhaps will make it into Ice Cream Sandwich. For the moment, there is no way around it, short of installing a custom ROM.

话虽如此,有一些解决方法.由于 Android 需要在任何蓝牙套接字(服务器客户端)发送数据之前进行配对,因此您的应用程序可以简单地尝试连接到已配对的设备.当然,大多数时候连接会失败,但如果配对设备在范围内,连接就会发生.我已经在我的一个应用程序中实现了这个,它似乎有效.我不确定这对电池寿命有何影响,但如果扫描之间有足够的时间,您应该没问题.

With that said, there are some workarounds. Since Android requires pairing before any Bluetooth socket (server or client) can send data, your app can simply try and connect to already paired devices. Sure, most of the time the connection will fail, but if a paired device is in range the connection will happen. I've implemented this in an application of mine and it seems to work. I'm not sure how this affects battery life, but with enough time between scans you ought to be okay.

我希望 Android 的未来版本不会有这种不必要的限制,因为它会阻止一些可能有趣的临时网络应用程序.

I'm hoping that future versions of Android won't have this unnecessary limitation as it prevents some potentially interesting ad-hoc networking applications.

这篇关于想让 Android 蓝牙在应用程序运行之前始终可见吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆