如何在 Android 中使用密码保护应用程序
我希望用户每次尝试进入应用程序时都输入密码。也就是说,每次应用程序从后台转到前台时,用户都必须输入密码,无论是按启动器图标还是长按主页键
实现了第一部分,因为启动器意图被触发,并且我在该活动的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在
onResume
调用中,设置loginCounter
+= 1,在onPause
中设置 -= 1。显示登录对话框。
在通知栏中,您设置了一个
Intent
来调用Activity
,对吗?只需在其中添加一个参数“isCalledByNotificationBar”作为布尔值即可。In your
onResume
call, set aloginCounter
+= 1, in youronPause
-= 1.if loginCounter == 0 => show Login Dialog.
In the Notification Bar you set an
Intent
to call theActivity
, correct? Simply add a parameter "isCalledByNotificationBar" as boolean in there.如果
onResume
不起作用,那么onWindowFocusChanged(boolean)
怎么样?If
onResume
doesn't work, how aboutonWindowFocusChanged(boolean)
?也许您应该做的是在重新进入应用程序时查看自您上次暂停应用程序的任何活动时更新的时间戳以来是否少于 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.