background accelerometer sensor reading for shaking detection

Hi, We have Bluetooth Hardware and we want to connect to that bluetooth device to open lock in the background when user shakes his phone.Is it possible to do that? I came accross such apps in the store, but i do not know how to do it. Regards.