在我的OnCreate我正在做
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(MydeviceReceiver, filter);
MydeviceReceiver的地方
private final BroadcastReceiver deviceReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
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);
if( !PairedDeviceNames.contains(device) && !newDevices.contains(device))
newDevices.add(device);
}
else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action))
{
Log.v(" ","discovery Finished ");
if(newDevices.size() != 0)
{
deviceList.invalidateViews();
sectionAdapter.notifyDataSetChanged();
}
else
{
Toast.makeText(YourActivity.this, "No New Devices Found", Toast.LENGTH_LONG).show();
}
}
}
};