Edmund 最新主题

推荐阅读

1 1747 2016-10-31
本帖最后由 Edmund 于 2016-10-31编辑

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); 

} 

}  
                } 
        };


0

0条回复