2012-11-01 144 views
8

几天前,我在Google Play商店下载了蓝牙智能扫描仪软件。在我的三星Galaxy S3手机上安装后,我可以成功扫描我的蓝牙LE设备。使用三星Galaxy S3创建与BluetoothLE设备的连接

即使我已经尝试过所有方法来扫描我的蓝牙LE设备,但我的电脑上并没有显示任何内容。所以我反编译这个软件,android.bluetooth包中有一个startLeDiscovery()的方法。但是我感到困惑的是,这种方法并没有在我的Android SDK 15

android.jar最后存在,我更换了BlutoothAdapter.class文件和BluetoothDevice.class文件android.jar与他们的蓝牙智能扫描软件,这样我就可以成功在Eclipse中调用startLeDiscovery()方法。源代码如下所示。

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); 
     } 
    }  
};` 

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

我恳请您的帮助,以解决长期困扰我们的问题。为了促进发展,我将在网站上提供我的android.jar。您将在android.bluetooth目录中看到startLeDiscovery()方法和其他方法。当然,android目录中还有一个com.samsung.bluetoothle包。

您可以下载android.jarhereMirror)。

回答

0

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

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

0

您需要在AndroidManifest.xml中有一个uses-library标签来告诉应用程序使用Galaxy S3蓝牙库。三星从不公开发布开发者的库,因此您必须制作自己的jar文件进行编译,但不要在您的apk包装中包含该jar。

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

访问过使用反射来得到你所需要的方法的引用,并呼吁他们这样,你是最好的BluetoothAdapter和BluetoothDevice类的方法。

相关问题