A few days ago I downloaded the Bluetooth Smart Scanner software on the Google Play Store. After installing Samsung Galaxy S3 on my phone, I was able to successfully scan my Bluetooth LE device.
Despite the fact that I tried all the ways to scan my Bluetooth Bluetooth device, nothing was displayed on my computer. So I decompiled this software, there was a startLeDiscovery() method in the android.bluetooth package. But I was confused that this method did not exist in my android.jar android sdk 15.
Finally, I replaced the BlutoothAdapter.class file and the BluetoothDevice.class file of the android.jar file with the Bluetooth Smart Scanner software so that I can successfully call the startLeDiscovery() method in Eclipse. Source code as 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 device on the Galaxy s3 phone, as I thought. Otherwise, I also found com.samsung.bluetoothle package com.samsung.bluetoothle . Similarly, I added it to android.jar . But I could not connect to my LE device using these methods in this package.
I kindly ask you to help solve this problem, which has been plaguing us for a long time. To facilitate development, I will be contributing my android.jar to the website. You will see the startLeDiscovery() method and other methods in the android.bluetooth directory. Of course, in the android directory there is also the com.samsung.bluetoothle package.
You can download the android.jar package here ( Mirror ).
bluetooth bluetooth-lowenergy
Miao sen
source share