Holster

The holster sensor returns a boolean value that indicates whether the device is currently in a holster.

A BPS event is generated when the holster sensor reports a new reading. You can determine if a BPS event was triggered by the holster sensor by calling holster_get_domain(). Once you've determined that the event is from the holster sensor, you can call holster_event_get_holster_status() to retrieve whether or not the device is currently in a holster.

The code sample below demonstrates how you can use the holster sensor in your app:

#include <stddef.h>
#include <bps/bps.h>
#include <bps/holster.h>

int main(void)
{
    int event_domain;
    unsigned int event_code;
    int holster_status;

    bps_initialize();

    // All BlackBerry 10 devices support holster events.
    holster_request_events(0);

    while (1)
    {
        bps_event_t *current_event = NULL;
        bps_get_event(&current_event, -1);

        event_domain = bps_event_get_domain(current_event);
        event_code = bps_event_get_code(current_event);

        if (event_domain == holster_get_domain()) {
            holster_status = 
                holster_event_get_holster_status(current_event);
            if (holster_status == HOLSTER_IN) {
                // Adjust app for operation while holstered.
            } else if (holster_status == HOLSTER_OUT) {
                // Adjust app for operation while out of holster.
            } else {
                // Unknown status; handle error.
            }
        }
    }

    holster_stop_events(0);
    bps_shutdown();
    return 0;
}                          
            

Last modified: 2013-12-21



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus