I'm totally new to Android Studio. My simple goal is to read a value from my BLE112 and display it in an app. I'm using Android Studio 2.4 Preview 7. I've taken the official example code for RxAndroidBLE and cut it way down, but still can't get it to compile. Any help/suggestions would be greatly appreciated.
It may be relevant to mention my end goal which is to feed these values into a RealTime graph at 1000 samples/second. I've already got the RealTime graph working with MPAndroidCharts. Just need the values...
These are the current errors, but I am pretty sure there are few more....
Error:(21, 52) error: package com.trello.rxlifecycle.android.ActivityEvent does not exist Error:(48, 41) error: cannot find symbol variable PAUSE
package com.example.monik.rx5;
import android.support.v7.app.AppCompatActivity;
import android.bluetooth.BluetoothGattCharacteristic;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import com.polidea.rxandroidble.RxBleConnection;
import com.polidea.rxandroidble.RxBleDevice;
import com.polidea.rxandroidble.RxBleClient;
import com.polidea.rxandroidble.utils.ConnectionSharingAdapter;
import java.util.UUID;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.subjects.PublishSubject;
import com.trello.rxlifecycle.android.ActivityEvent.PAUSE;
public class MainActivity extends AppCompatActivity {
private static String macAddress = "00:07:80:F2:92:D8";
private UUID characteristicUuid;
private PublishSubject<Void> disconnectTriggerSubject = PublishSubject.create();
private Observable<RxBleConnection> connectionObservable;
private RxBleDevice bleDevice;
private RxBleClient bleClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
characteristicUuid = UUID.fromString("F90EA017-F673-45B8-B00B-16A088A2ED61");
bleClient = RxBleClient.create(this);
bleDevice = bleClient.getBleDevice(macAddress);
connectionObservable = prepareConnectionObservable();
onConnectToggleClick();
onReadClick();
}
private Observable<RxBleConnection> prepareConnectionObservable() {
return bleDevice
.establishConnection(false)
.takeUntil(disconnectTriggerSubject)
.compose(bindUntilEvent(PAUSE))
.compose(new ConnectionSharingAdapter());
}
public void onConnectToggleClick() {
if (isConnected()) {
triggerDisconnect();
} else {
connectionObservable
.flatMap(RxBleConnection::discoverServices)
.flatMap(rxBleDeviceServices -> rxBleDeviceServices.getCharacteristic(characteristicUuid))
.observeOn(AndroidSchedulers.mainThread())
//.doOnSubscribe(() -> connectButton.setText(R.string.connecting))
.subscribe(
characteristic -> {
Log.i(getClass().getSimpleName(), "Hey, connection has been established!");
},
this::onConnectionFailure,
this::onConnectionFinished
);
}
}
public void onReadClick() {
if (isConnected()) {
connectionObservable
.flatMap(rxBleConnection -> rxBleConnection.readCharacteristic(characteristicUuid))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(bytes -> {
TextView tv = (TextView) findViewById(R.id.read_output);
tv.setText(new String(bytes));
}, this::onReadFailure);
}
}
private boolean isConnected() {
return bleDevice.getConnectionState() == RxBleConnection.RxBleConnectionState.CONNECTED;
}
private void onConnectionFailure(Throwable throwable) {
}
private void onConnectionFinished() {
}
private void onReadFailure(Throwable throwable) {
}
private void triggerDisconnect() {
}
}