怎么用android获取bluetooth的信号强度
2016-05-07 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
1.oncreate面增加 注册扫描广播
public void
onCreate(Bundle savedInstanceState) {
// 注册始发现广播
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED);
this.registerReceiver(mReceiver, filter);
}
2.新建BroadcastReceiver广播象并实现面onreceive,onreceiverssi(信号强度)
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context
context, Intent intent) {
String action =
intent.getAction();
//设备始扫描
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
//IntentblueDevice象
BluetoothDevice device = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if
(device.getBondState() != BluetoothDevice.BOND_BONDED) {
//信号强度
short rssi =
intent.getExtras().getShort(
BluetoothDevice.EXTRA_RSSI);
}
}
}
};
public void
onCreate(Bundle savedInstanceState) {
// 注册始发现广播
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED);
this.registerReceiver(mReceiver, filter);
}
2.新建BroadcastReceiver广播象并实现面onreceive,onreceiverssi(信号强度)
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context
context, Intent intent) {
String action =
intent.getAction();
//设备始扫描
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
//IntentblueDevice象
BluetoothDevice device = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if
(device.getBondState() != BluetoothDevice.BOND_BONDED) {
//信号强度
short rssi =
intent.getExtras().getShort(
BluetoothDevice.EXTRA_RSSI);
}
}
}
};
晓网科技
2024-10-17 广告
2024-10-17 广告
ZigBee作为一项新型的无线通信技术,其具有传统网络通信技术所不可比拟的优势,既能够实现近距离操作,又可降低能源的消耗。又如,相较于蓝牙等无线通信技术,ZigBee无线通信技术可有效降低使用成本, 即便数据处理的速率并不高,然而,值得肯定...
点击进入详情页
本回答由晓网科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询