Get headphone state with Snapshot API
suggest change// Remember to initialize your client as described in the Remarks section
Awareness.SnapshotApi.getHeadphoneState(client)
.setResultCallback(new ResultCallback<HeadphoneStateResult>() {
@Override
public void onResult(@NonNull HeadphoneStateResult headphoneStateResult) {
if (!headphoneStateResult.getStatus().isSuccess()) {
Log.e(getClass().getSimpleName(), "Could not get the headphone state.");
return;
}
int state = headphoneStateResult.getHeadphoneState().getState();
Log.i(getClass().getSimpleName(), "Headphone connection state: " +
(state == HeadphoneState.PLUGGED_IN));
}
});
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents