How to lock android buttons/phone from code (screen lock)? [duplicate] - java

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Lock the android device programatically
I have made a simple Android app with a pin-code/screen lock. The user have to write a password to lock the phone and then repeat it to unlock the phone. The problem is that the user still can press back, home (etc) to exit the app without writeing the code. How can I prevent this?

You can block the back button by overwriting dispatchKeyEvent() in your Activity class, and returning true if event.getKeyCode() is equal to KeyEvent.KEYCODE_BACK. But you cannot block the Home button from going to the home page.
I have heard of some trickery where you register your application as a receiver of the android.intent.category.HOME intent. This would cause the Android OS to load your activity if the user presses the home button. If you can get this to work, you could then load the "actual" home screen if the user has entered the correct password. This approach is likely to behave differently on different devices and Android versions, however, and it probably would do nothing to stop the Hold-Home task list from appearing.
The bottom line is the Android OS has been designed to prevent just the thing you are trying to do: an application should not be able to take control over the phone and prevent other applications (especially the Phone) from running.

It's my understanding that you cannot block the home key as it's a security feature that allows the user to always exit an app. Pressing home will not close the activity however.

the guys who created free "Toddler lock" apk somehow managed to did it - download and see for yourself :)
when you run it, it asks for permission to run as home app and you need to check the box "use as default". To exit from app, you need to press on all 4 corners of the screen. All the buttons but power one are locked. So there is a way for sure to do that!
he explains to users how it works here:
http://www.toddlerlock.com/3.html

Related

How can Take permission using an alert Box at just destroy the application in Android

I just want to show an alert box at just killing the application in android.
It's like a Notepad application, if we simply kill the app (on clicking the close button) then we get an alert box asking for save changes.
I just want to add same thing in my application.I have tried onBackPressed() and its working fine on clicking on Back Button. But I need same thing on closing the application.
There is now way to be sure if the app is being closed but you can place a check if the application is in foreground or not which is a better metric IMHO as this tells you when the user moved away from your application.
To check the ProcessLifeCycleOwner this will help you find state of process. You can check this Github sample or this stackoverflow question in how to use it.

Is there a way to detect when a popup window appears in Android

I started a project of a windows program that connects to an android phone and gives the user information
about it, so I want to display all of the popups that appere on the phone. to do this I need the app version of the program to catch them somehow and give me the name of the app that sent the popup and the popup's contant. is it possible?
it would be kind of security issue if any app could do that... you can try with AccessibilityService with some permissions for reading screen/running Activities and checking style of every Activity is this "popup", but note that some of them are just DialogFragments. So I doubt you can recognize "popups" this way in a reliable way. Look for AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED for more info

How to not let the user exit my app?

Hi i need something to don't let users exit my app without pressing the button exit. Basicly if they use home or any other button the app can't exit. How can i make this? Im using android studio and im new to this language.
The only thing you can do is override the onBackPressed method but unfortunately, you can't stop the home button from closing the app unless the phone is rooted or something. But when you do close the app with the home button it is still in Android's memory which prevents cold starts the next time the user opens the app. I am not sure why the information would be helpful though.

Detect when a failed unlock happens

I've been looking around for a while to find out what happens when a user fails to unlock the phone.
Basically I'm trying to take a picture if a user fails to authenticate. But all I can find is ACTION_USER_PRESENT - Does anyone know if this is possible?
Thanks
You can't access the login attempts of the android lockscreen.
If you want to build an app that does that you have to create your own lockscreen. However, this is not a "real" lockscreen you can't edit in the android settings. This would be an App which acts like a lockscreen and has the same permissions. Because you can check if a phone is locked, that way the app would activate its own "lockscreen" (which is basically a normal form with many permissions) whenever the phone gets locked (you probably have to deactivate the original lockscreen).
Look into this link, there you have all options regarding the original lockscreen.

how to develop a replacement for the android lock screen [duplicate]

This question already has an answer here:
Custom Lock Screen Implementation Techniques
(1 answer)
Closed 7 years ago.
I need to put my app on the lock screen (android 2.2)!
I think there are two options for do this:
Develop an app to replace android's lock screen. This app whould be called when the off button is pressed.
Insert my app button into android's actual lockscreen, so, my app would work, even if the screen is locked, and eventually, my app could unlock the screen.
I don't know how to do it, but I do know it is possible, since some music players can be downloaded and the music player options are in the lockscreen.
Can anybody help me out?
thanks.
(1) is totally feasible and there are many lockscreen alternatives apps available.
(2) will depend on what lockscreen are you talking about and what is what your app does. Firmware lockscreens do not allow usually widgets in them. At most, they have a method to interact with the call/sms log and the music player, but that's it.
So, unless your app does one of those two, your only option is pretty much (1).

Categories