使用Samsung Galaxy S3创建与BluetoothLE设备的连接

Mia*_*Sen 8 bluetooth bluetooth-lowenergy

几天前,我在Google Play商店下载了Bluetooth Smart Scanner软件.在我的三星Galaxy S3手机上安装后,我可以成功扫描我的蓝牙LE设备.

尽管我已经尝试过扫描我的蓝牙LE设备的所有方法,但我的计算机上没有显示任何内容.所以我反编译了这个软件,startLeDiscovery()包中有一个方法android.bluetooth.但令我困惑的是,这个方法在我android.jar的android sdk 15中不存在.

最后,我用Bluetooth Smart Scanner软件替换了它们的BlutoothAdapter.class文件和BluetoothDevice.class文件android.jar,这样我就可以startLeDiscovery()在Eclipse中成功调用该方法.源代码如下图所示.

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);
        }
    }       
};`
Run Code Online (Sandbox Code Playgroud)

事实证明,我成功地在Galaxy s3手机上扫描了我的蓝牙LE设备,就像我想的那样.否则,我发现还有一个com.samsung.bluetoothle包.同样地,我把它添加到我的android.jar.但我无法使用该软件包中的那些方法连接到我的LE设备.

我恳请你帮忙解决困扰我们很久的这个问题.为了促进开发,我将android.jar在网站上贡献自己的力量.您将startLeDiscovery()android.bluetooth目录中看到方法和其他方法.当然,目录中还有一个 com.samsung.bluetoothleandroid.

你可以在这里下载android.jar包(镜像).

Fem*_*emi 0

android.jar文件被认为是您的 Android 设备上已经可用的类:如果我没记错的话,这些类不包含在为您的应用程序生成的 APK 中,因此添加这些类com.samsung.bluetoothle不会android.jar使它们添加到您的应用程序中。

android.jar为什么不直接从 Samsung 网站 ( http://developer.samsung.com/ble ) 下载整个 SDK 并按照推荐的方式使用它,而不是反编译并将其添加到文件中呢?