最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

lockscreen - Is there any way for an android with a nearby beacon to lock the screen if the phone moves away from the beacon - S

programmeradmin3浏览0评论

With a beacon close to an Android phone, is it possible to lock the phone's screen if the beacon is moved away from it? Does the Android system allow this? I've tried the tasker app but it seems it needs some plugins and I didn't find it.

With a beacon close to an Android phone, is it possible to lock the phone's screen if the beacon is moved away from it? Does the Android system allow this? I've tried the tasker app but it seems it needs some plugins and I didn't find it.

Share Improve this question asked Jan 20 at 12:33 HogHog 91 bronze badge 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Bot Commented Jan 21 at 3:56
Add a comment  | 

1 Answer 1

Reset to default 0

Yes, it is possible to lock an Android phone when a Bluetooth beacon goes out of range.

The basic steps are:

  1. Scan for Bluetooth Beacons using a Foreground Service. The foreground service is necessary to keep the app active in the background so it can lock the phone quickly if the beacon is no longer seen by the scan. There is no other viable way for third party apps to do this due to background Bluetooth scanning restrictions in Android. You cannot tell if a beacon disappears unless you constantly scan for it.

  2. Watch for the scanned beacons to not be seen for several seconds, and when that happens trigger a screen lock. Using the Android Beacon Library, you can get notifications of when you "exit a beacon region", meaning it has not been seen in at least 30 seconds.

  3. Use the Android DevicePolicyManager API to get permission from the user to manage the device and lock the screen. This is a bit tricky to set up and get permission from the user. You have to add some entries to your AndroidManifest.xml, and prompt the user to allow this on the first time launch. But once you do so, you can use it like this:

  devicePolicyManager = getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
  devicePolicyManager.lockNow()
  1. Hook in the beacon region exit code to lock the screen.

I have a sample app on Github that does this using the Android Beacon Library for scanning. It shows you how to set up the beacon scanning and to set up the DevicePolicyManager.

https://github.com/davidgyoung/android-lock

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论