5

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.

Hiren Patel
  • 50,794
  • 21
  • 170
  • 147

2 Answers2

2

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.

Hiren Patel
  • 50,794
  • 21
  • 170
  • 147
0

Your app is pretty much a sandbox within your device. Listening to unlock states is not tied to anything within your app.

Your next best hope is to do something like this, but I would not recommend it as it most likely violates private API's (This is iOS only): https://stackoverflow.com/a/14271705/1363779

kevinl
  • 4,174
  • 6
  • 36
  • 53