A few days ago, I downloaded the Bluetooth Smart Scanner software on Google Play Store. After installed it on my Samsung Galaxy S3 phone, I could scan my Bluetooth LE device successfully.
Even though I had tried all ways to scan my bluetooth LE device, there was nothing displayed on my computer. So I decompiled this software, there was a startLeDiscovery() method in the package android.bluetooth. But what confused me was that this method didn't exist in my android.jar of android sdk 15.
At last, I replaced the BlutoothAdapter.class file and BluetoothDevice.class file of android.jar with them of Bluetooth Smart Scanner software, so that I could successfully call the startLeDiscovery() method in Eclipse. The source code as shown below.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
IntentFilter intent = new IntentFilter();
intent.addAction(BluetoothDevice.ACTION_FOUND);
intent.addAction(BluetoothDevice.EXTRA_UUID);
intent.addAction(BluetoothDevice.ACTION_GATT_PRIMARY_UUID);
registerReceiver(searchDevices, intent);
//bluetooth.discovery();
bluetooth.startLeDiscovery();
}
private BroadcastReceiver searchDevices = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
BluetoothDevice device = null;
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String msg = device.getName()+"\n"+device.getAddress();
Log.i("hella",msg);
bluetooth.cancelDiscovery();
connectDevice(device);
}
}
};`
It turned out that I successfully scanned my bluetooth LE device on Galaxy s3 phone