private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// When discovery finds a device
Log.v("fdghdg22", "11");
Toast.makeText(Main3Activity.this, "已点击", Toast.LENGTH_LONG).show();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Log.v("fdghdg11", "11");
List<String>list =new ArrayList<>();
list.add(device.getName() + "\n");
ArrayAdapter<String> mArrayAdapter=new ArrayAdapter<String>(Main3Activity.this,android.R.layout.simple_list_item_1,list);
// Add the name and address to an array adapter to show in a ListView
// mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
ListView listView3=(ListView)findViewById(R.id.listView2);
listView3.setAdapter(mArrayAdapter);
}
}
};
public void onResume(){
//注册广播接收器
Log.v("fdtrtrdg", "11");
// IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);//注册广播接收信号
// intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);//本地蓝牙适配器已经开始对远程设备的搜寻过程。
// this.registerReceiver(mReceiver, intentFilter);//用BroadcastReceiver 来取得结果
//注册广播接收器(监听蓝牙状态的改变)
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
this.registerReceiver(mReceiver, filter); // 不要忘了之后解除绑定
super.onResume();
}
warning:BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.SIG_STR flg=0x10 (has extras) } to com.xingin.xhs/org.daemon.receiver.ConnectivityReceiver