The only way we can come somewhat near to the solution is using.Google Awareness API wont solve the problem as it has a entirely different usage.
- Light sensor(Environment sensor)
- Proximity sensor(Position sensor)
The Android platform provides four sensors that let you monitor various environmental properties. You can use these sensors to monitor
- relative ambient humidity
- luminescence
- ambient pressure
- ambient temperature
All four environment sensors are hardware-based and are available only if a device manufacturer has built them into a device. With the exception of the light sensor, which most device manufacturers use to control screen brightness, environment sensors are not always available on devices. Because of this, it's particularly important that you verify at run time whether an environment sensor exists before you attempt to acquire data from it.
Light sensor can be used to calculate the light intensity.For example many mobile phones having Auto brightness mode function, this function work on light sensor that will adjust screen brightness as per light intensity.
There are many unites such as Lux,candela,lumen etc, to measure light intensity.
Considering this there will be considerable difference in light intensity when you phone in in pocket or outside pocket.
Although the same will happen for the case when you are operating phone is dark room. or at those place where the light intensity is quite low. hence to distinguish among such cases is the real challenge.You can use other environments sensor in combination of light sensor to come to an effective outcome.But i assume an accurate solution is dicey.
To study more about these sensors kindly refer to following links
https://developer.android.com/guide/topics/sensors/sensors_environment.html
https://developer.android.com/guide/topics/sensors/sensors_position.html
Google awareness API wont work for this case. as provides entirely different solution.
It provides two API
You can use the Snapshot API
to get information about the user's current environment. Using the Snapshot API, you can access a variety of context signals:
- Detected user activity, such as walking or driving.
- Nearby beacons that you have registered.
- Headphone state (plugged in or not)
- Location, including latitude and longitude.
- Place where the user is currently located.
- Weather conditions in the user's current location.
Using the Fence API
, you can define fences based on context signals such as:
- The user's current location (lat/lng)
- The user's current activity (walking, driving, etc.).
- Device-specific conditions, such as whether the headphones are
plugged in.
- Proximity to nearby beacons.