android注册蓝牙广播无响应,android – 动态注册广播接收器不起作用–BluetoothDevice.ACTION_FOUND...
使用Log类跟踪Runtime显示onReceive()方法没有调用,为什么?动态注册广播接收器private void discoverDevices () {Log.e("MOHAB","BEFORE ON RECEIVE");mReceiver = new BroadcastReceiver() {public void onReceive(Context context, Intent i
使用Log类跟踪Runtime显示onReceive()方法没有调用,为什么?
动态注册广播接收器
private void discoverDevices () {
Log.e("MOHAB","BEFORE ON RECEIVE");
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
Log.e("MOHAB","ON RECEIVE");
String action = intent.getAction();
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// Add the name and address to an array adapter to show in a ListView
Bluetooth b = new Bluetooth(device.getName(),device.getAddress());
list.add(b);
}
}
};
Log.e("MOHAB","create intentFilter");
// Register the BroadcastReceiver
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter); // Don't forget to unregister during onDestroy
}
更多推荐
所有评论(0)