Alex Rivera | Logout

create a connection to a BluetoothLE device using Samsung Galaxy S3

Asked 2012-11-01T02:03:43.680
8

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

Edit
Report

1 Answer

0

The android.jar file is considered to be classes that are ALREADY available on your Android device: if I recall correctly those classes are not included in the APK that is generated for your app, so adding the com.samsung.bluetoothle classes to android.jar will not make them get added to your app.

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

answered 2013-05-29T17:32:24.180

Your Answer