如何在 Android 中使用密码保护应用程序

发布于 2024-10-05 00:21:32 字数 285 浏览 0 评论 0原文

我希望用户每次尝试进入应用程序时都输入密码。也就是说,每次应用程序从后台转到前台时,用户都必须输入密码,无论是按启动器图标还是长按主页键

实现了第一部分,因为启动器意图被触发,并且我在该活动的 onRestart 中收到回调。

但长按 home 键并启动不会提供 onRestart 回调。

另外,如果用户通过按通知栏上的通知来启动应用程序会怎么样。在用户点击通知之前,如何区分应用程序最初是在后台还是前台

I want the user to enter a password everytime he tries to enter the application. That is, the user must enter the password everytime the app comes to foreground from background, be it by pressing the launcher icon or long-pressing the home key

I sort-of achieved the first part because the launcher intent is fired and i get a callback in onRestart of that activity.

But by long-pressing home key and launching the does not provide callback to onRestart.

Also what if the user launches the app by pressing the notification from, the notification bar. How do I distinguish whether the app was originally in background or fore-ground before the user clicked the notification

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

国际总奸 2024-10-12 00:21:32

onResume 调用中,设置 loginCounter += 1,在 onPause 中设置 -= 1

。显示登录对话框。

在通知栏中,您设置了一个 Intent 来调用 Activity,对吗?只需在其中添加一个参数“isCalledByNotificationBar”作为布尔值即可。

In your onResume call, set a loginCounter += 1, in your onPause -= 1.

if loginCounter == 0 => show Login Dialog.

In the Notification Bar you set an Intent to call the Activity, correct? Simply add a parameter "isCalledByNotificationBar" as boolean in there.

时光与爱终年不遇 2024-10-12 00:21:32

如果 onResume 不起作用,那么 onWindowFocusChanged(boolean) 怎么样?

If onResume doesn't work, how about onWindowFocusChanged(boolean)?

夏末 2024-10-12 00:21:32

也许您应该做的是在重新进入应用程序时查看自您上次暂停应用程序的任何活动时更新的时间戳以来是否少于 30 (?) 秒。如果较少,则不要要求输入密码。我认为这个短时间窗口可能会平滑一些您不想注销的转换。

Perhaps what you should do is on re-entry into the application see if it's been less than 30 (?) seconds since a timestamp that you update when any activity of your application was last paused. If it's been less, don't ask for a password. Thinking being that this short time window might smooth over some transitions you don't want to log out on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文