Create a connection to a BluetoothLE device using Samsung Galaxy S3

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 ).

+8
bluetooth bluetooth-lowenergy
source share
2 answers

The android.jar file is considered a class that is ALREADY available on your Android device: if I remember correctly that these classes are not included in the APK that was created for your application, so adding the com.samsung.bluetoothle classes to android.jar will not add them to your application.

Instead of decompiling and adding to the android.jar file, why not just download the entire SDK from the Samsung website ( http://developer.samsung.com/ble ) and just use it in the recommended mode?

0
source share

In your AndroidManifest.xml, you need to use the use library tag to tell the application that it uses the Galaxy S3 bluetooth library. Samsung has never publicly released a library for developers, so you need to make your own jar file for compilation, but not include the jar in the packaging of your apk.

 <uses-library android:name="com.samsung.bluetoothle.BluetoothLEClientProfile" android:required="false" /> 

To access the BluetoothAdapter and BluetoothDevice methods, it is best to use reflection to get references to the methods you need and call them that way.

0
source share

All Articles