I need to lock the Android phone when the user leaves a defined WiFi area
I need to prevent the user from unlocking the phone when he/she is out side the defined WiFi area
I need to unlock the phone when user is back to the WiFi area
I guess list items 1 and 3 can be done programmatically.
Is it possible to do the 2nd item?
Locking can be done using this method: How to lock the screen of an android device
Unlocking look here: How to display Activity when the screen is locked?
For your problem 2, i see 2 solutions
a. If the user unlocks the screen, a message is fired: check at that moment if you are in the area and if not, instantly lock again
b. create your own locksreen with no possibility to unlock yourself
I need to prevent the user from unlocking the phone when he/she is out side the defined WiFi area
Fortunately, this is not supported, for obvious security reasons.
You are welcome to create your own home screen that offers different behavior when inside/outside a defined area and use that in lieu of trying to prevent a phone from being unlocked. However, the user is welcome to remove that home screen by booting their device into safe mode and uninstalling your app.
I had done similar thing in past but dont have the code right now so cant help in that respect. What I did is implement the app as Car Dock that will make the Home button override unless car-dock mode is dis-abled. I hope this will help, for code google it you definitely find resources
I guess this will help you out. This is just for Disabling the Lock Programmatically.Disable Screen Lock
private Window w;
public void onResume() {
w = this.getWindow();
w.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
w.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
w.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
super.onResume();
tToast("onResume");
}
Related
i have used some smartphone with this cool function, double tap to screen off, then double tap again to turn on. Really dont need to use physical power button (many user want to avoid this) But not every phone have it built in, my question is can we create an app for a phone without this function and without root?
google search resulted all trash
No. There's no way to get taps when your app isn't the topmost activity, much less when the screen is off.
first of all, I would like to tell you, what I want to do: I want to get some behavior of iOS on my Android device. Of course, it's just a little detail.
The behavior I talk about is on iOS like that:
The user doesn't use the device
After a short time, the device dims its screen.
Now the user has to tap somewhere on the display to reactivate the device.
THIS IS THE BEHAVIOR I WANT If the user taps on the screen, the screen
will just become active again. The tap itself will NOT cause any other action.
On Android, it's almost the same behavior. Except for step 4: If the user taps on the screen to prevent standby, the tap will already cause actions in the app or home screen or wherever you are.
I decided to develop a small Accessibility Service. This service will show an overlay when the device is inactive and dims its display. Clicking on the overlay will just close it. The overlay itself is no problem and it's already working.
My problem is: I don't know how to find out when the display is dimmed because of inactivity.
My ideas are:
Listen to the Intent.ACTION_SCREEN_OFF event (https://developer.android.com/reference/android/content/Intent).
--> It's working. But it's too late :-( The screen is already completely off when the event has been fired.
Check, if the device is inactive/idle.
--> Is there any possibility to get the status of the whole device? I haven't found anything about that.
Or maybe somebody has completely other ideas?
Thanks for your help.
Greetings
Patrick
You can keep the window screen on & using a TimerTask, dim the brightness of the window manually by some % every, say 5 seconds...
Then when the taps on overlay, Increase the brightness
I would like to know if it is possible to let the screen turn off (as setted in device parameters) but to prevent the phone to lock while my application is running in front.
So, when something happen in the app, I can turn on the screen and the user dont have to unlock his phone. (It is a driving application, so it would be dangerous to make the user unlock the phone while driving)
Thanks!
EDIT:
I dont want the screen to stay on : I want to be able to turn it on and when I do, that I dont have to unlock the screen.
Use this in your activity:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| +WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
I hope it will help. This will prevent your app to lock while your activity is visible.
There are many ways to do this.. One of the way is to set this flag in your activities oncreate.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
For the other ways to keep your screen on.. Link.
I'm writing an anti theft app, and I want when sim card is changed a dialog opens on boot and tell the finder to bring back the phone. This activity must be unleavable, so he can't leave it unless the correct code is entered.
Other situation is when user send a lock SMS to the phone.
I know how a device admin can lock the phone, but lock don't tell the message and the password can't be entered. And lock may not have a password or pattern so the finder can pass it easily.
Maybe a combination of device lock and a full screen activity which disable the keyguard do the job?
In my research, without being installed at the OEM level, you can't make it 100% un-leavable, just really annoying.
In an app I wrote for businesses which use a kiosk, since we weren't at the OEM level, we just kept the menu bar hidden and set the app to be loaded whenever Home was hit. Keeping the menu bar hidden was a pain, but was achieved by making it invisible and then when re-triggered, making it go away after 1 second. It's still able to be exited by hitting the clock in that 1 second, though. :(
If I want to write a Screensaver or Lockscreen. Is there a way to prevent the home key from going back to the launcher?
Simple: when you enter the activity, call
getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
and when you exit the activity, call
getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION);
Taking over the home key is an Android no-no.
The only screensaver in Android should be the screen going off. Why would anyone want to run down their battery instead of just pressing one button to turn the screen off and doing the same to turn it back on? It just doesn't make sense on a device with a very limited power supply to run a screensaver.
I'm not quite sure but from what I have read online, custom lock screens can only be done in custom firmware or rooted applications.