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

后端 未结 2 1481
Happy的楠姐
Happy的楠姐 2021-01-14 21:12

Concept:

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

相关标签:
2条回答
  • 2021-01-14 21:46

    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.

    0 讨论(0)
  • 2021-01-14 22:04

    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

    0 讨论(0)
提交回复
热议问题