after splash screen i have scan activity in that after scan i will get list of ble devices.when on click on particular item it moves to device control activity.when move to it i want to add progress bar/something like displaying connecting... and the following is my code in device control activity.
private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {
// Show all the supported services and characteristics on the user interface.
connected_alert();
check_forservices(mBluetoothLeService.getSupportedGattServices());
} else if (BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action)) {
mConnected = false;
updateConnectionState(R.string.disconnected);
invalidateOptionsMenu();
create_alert();
} else if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) {
mConnected = true;
updateConnectionState(R.string.connected);
invalidateOptionsMenu();
} else if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) {
displayData(intent.getStringExtra(BluetoothLeService.EXTRA_DATA));
}
}
};
and the following is my connected_alert() method.
public void connected_alert(){
progressDialog = ProgressDialog.show(DeviceControlActivity.this, "", "Connecting...");
new Thread() {
@Override
public void run() {
try{
mBluetoothLeService.connect(mDeviceAddress);
sleep(1000);
if(true)
connection_alert();
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
// dismiss the progress dialog
progressDialog.dismiss();
}
}.start();
}
but while doing this i got error.it is Can't create handler inside thread that has not called Looper.prepare()