Search code examples
react-nativelockscreen

React Native: How to detect device lock/unlock event?


Concept:

My application needs to record user activities on phone. Activities contain Foreground, Background, Kill, Lock and Unlock.

What I did:

I am able to record application's Foreground, Background and Kill states using AppState library.

Requirement:

I need to perform actions on device Lock/Unlock states. Unfortunately I am unable to listen device lock and unlock event in above library.

Any help would be appreciated.


Solution

  • Since that day I couldn't find any way to detect Lock/Unlock event in React native.

    Solution:

    1. We've created sample modules in Android and iOS separate (Native code to get Lock/Unlock events)
    2. Using Android studio / XCode we've exported as React native modules
    3. Imported these modules in React native

    It works fine for us.

    Hope this would help you.