Kilka dni temu pobrałem oprogramowanie Bluetooth Smart Scanner w sklepie Google Play. Po zainstalowaniu go na telefonie Samsung Galaxy S3 mogłem pomyślnie zeskanować urządzenie Bluetooth LE.utwórz połączenie z urządzeniem BluetoothLE za pomocą Samsung Galaxy S3
Mimo że próbowałem wszystkich sposobów skanowania mojego urządzenia Bluetooth LE, na moim komputerze nie było nic. Tak więc, dekompilowałem to oprogramowanie, w pakiecie znajdowała się metoda startLeDiscovery()
w pakiecie android.bluetooth
. Ale co mylić mnie było to, że ta metoda nie istnieje w moim android.jar
Android SDK 15.
wreszcie wymieniłem plik BlutoothAdapter.class
i BluetoothDevice.class
plik android.jar
z nimi oprogramowania Bluetooth Smart Scanner, abym mógł z powodzeniem wywołaj metodę startLeDiscovery()
w środowisku Eclipse. Kod źródłowy, jak pokazano poniżej.
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);
}
}
};`
Okazało się, że z powodzeniem zeskanowałem moje urządzenie Bluetooth LE na telefonie Galaxy S3, tak jak myślałem. W przeciwnym razie znalazłem tam również pakiet com.samsung.bluetoothle
. W ten sam sposób dodałem go do mojego android.jar
. Ale nie mogłem połączyć się z moim urządzeniem LE za pomocą tych metod w tym pakiecie.
Uprzejmie proszę o pomoc w rozwiązaniu tego problemu, który nęka nas przez długi czas. W celu ułatwienia rozwoju, przyczynię mój android.jar
na stronie internetowej. Zobaczysz metodę startLeDiscovery()
i inne metody w katalogu android.bluetooth
. Oczywiście istnieje również pakiet com.samsung.bluetoothle
w katalogu android
.
Możesz pobrać pakiet android.jar
here (Mirror).