0

I know this problem is really vague but i am really looking for a informative answer of how to do it.. or stuff like that..

A question on Stackoverflow already..

There are two ways to do it. One is the on Head wake and the other is notification glance. Can these be accessed for glassware apps. Can we basically control the glass rear view camera when inside an app and verify whether a user has actually worn it rather than just having a vague access with head wake or notificaiton glance.

Community
  • 1
  • 1
medampudi
  • 399
  • 3
  • 15

1 Answers1

3

You can listen to the ACTION_ON_HEAD_STATE_CHANGED broadcast Intent to know if the user is wearing Glass or not: this requires that the user has turned this feature on.

To do so, create a BroadcastReceiver to handle the Intent and register it within your Activity:

BroadcastReceiver mOnHeadStateChangedReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        boolean isOnHead = intent.getBooleanExtra(Intents.EXTRA_IS_ON_HEAD, false); 

        // Process the intent.
    }
};

@Override
protected void onResume() {
    super.onResume();
    IntentFilter filter = new IntentFilter(Intents.ACTION_ON_HEAD_STATE_CHANGED);
    registerReceiver(mOnHeadStateChangedReceiver, filter);
}

@Override
protected void onPause() {
    unregisterReceiver(mOnHeadStateChangedReceiver);
    super.onPause();
}

This example is using an Activity but this can be done in a Service or anywhere you have access to a valid Context.

Alain
  • 6,044
  • 21
  • 27