Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
getObservablePhoneState()
.subscribe(integer -> Log.i(TAG, "onNext = " + stateToString(integer)));
private Observable<Integer> getObservablePhoneState() {
return Observable.create(emitter -> {
Log.i(TAG, "Started emitting");
Log.i(TAG, "Emitting TEST = 1");
emitter.onNext(1);
Log.i(TAG, "Emitting TEST = 2");
emitter.onNext(2);
Log.i(TAG, "Observable. Setup phoneStateListener");
final TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(new PhoneStateListener() {
//@Override
public void onCallStateChanged(int state, String incomingNumber) {
//super.onCallStateChanged(state, incomingNumber);
Log.i(TAG, "listener = " + stateToString(state));
if (emitter.isDisposed()) {
return;
}
emitter.onNext(state);
}
}, PhoneStateListener.LISTEN_CALL_STATE);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.