I'm facing a issue on the devices with Marshmallow + and i'm trying to find out a solution programmatically. When ever the code executes for asking user a dangerous permission a "screen overlay detected" popUp appears and takes the user to "Draw Over apps" Settings. It's hard for a user to determine which app to select to turn off the overlay feature. A very ordinary user might get confused what to do and could see it as a gimmick, would simply press back button and kill the app. Turn out to be a bad user experience.
It may be not rally necessary to turn off this feature. Is there a way to handle this programmatically. By pass this Popup and stay on the main track?
Related
iam developing screenlock app for android using a React Native and a little annoyed with the screen pinned dialog that always appears, is there a way to just get rid of it? so what I really want is no dialogue interaction at all with the user
enter image description here
If you're calling startLockTask() and your device isn't set up as a dedicated device with your app whitelisted, then no you can't prevent it:
Otherwise, the current task will be launched into screen pinning mode. In this case, the system will prompt the user with a dialog requesting permission to use this mode. The user can exit at any time through instructions shown on the request dialog.
The dialog is there to help users understand what's happening, give permission for the app to take over their screen, and know how to get out of it later. It's baked into Android by design, so malicious apps can't cause problems - it's just a limitation you have to deal with, unless you're working with a dedicated device (which can be set up to give apps more control and users less)
Have you thought about immersive mode instead, where you hide the nav bar? The user can get out of that too by swiping to reveal the controls, but it's less intrusive. There's no way to automatically lock the user's screen with no interaction though
I'm working on a smartphone rental service.
When the user unlocks the app
1) I would like to launch xxx app, instead of the android home screen
2) Would like to prevent the user from returning to the dashboard of the app (when they press the device home button)
Possible solution I could think of
1) Open the app before passing it to the customer
2) Prevent the app from returning to android home screen when device home button is press by redirecting it to the app dashboard when the home button event is triggered.
Detect home button press in android
This code only detects the event but didn't prevent the user from going back to the home screen.
#Override
protected void onUserLeaveHint()
{
Log.d("onUserLeaveHint","Home button pressed");
super.onUserLeaveHint();
}
Hope it's not something I need to do on the OS level.
This actually something i've been working on for well over a year. It is not an easy task to accomplish nor is it going to be perfect, there is almost always a way out of the app without direct ROM access.
If you have access to all the hardware before the customer get's it you can use "Device Owner/Provisioning" which makes it much easier
https://source.android.com/devices/tech/admin/provision.html
Then with device owner you can use "Screen Pinning" without user prompting as well as disable specific apps etc.
https://developer.android.com/about/versions/android-5.0.html#ScreenPinning
Other than these, a recommended way is to
Request "App Usage Access" when starting the app (Settings>Security)
This will allow you to get the current "top" package, i.e. which app is running
Start a service which periodically checks the top app to check if it != the allowed app
If it is not your allowed app, then resume focus on your app
Of course there is other bits to consider, blocking of status bar (drawing an invisible view on top works well), prevention of access to system dialogues, requesting of "Device Admin" such that you can prevent uninstall of the main app without permission etc.
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. :(
There is an app on the Google "Play Store" called "Screen Filter", which is designed to cover the entire screen with some translucent black, to allow the screen to be dimmer than the minimum brightness.
It does this using a permission called "Display System-Level Alerts".
Where is the documentation that allows me to do this in my app?
Can this "system-level alert" intercept touch events? This is so I can get my app to take over an Android that is supposed to stay in our building.
I like this approach because it prevents the phone from being turned off before it is turned over (which would trigger an alarm), unless of course there is a hammer involved.
Docs for Manifest.Permission show that the SYSTEM_ALERT_WINDOW is the permission you are looking for. You would declare this permission in the Manifest and then in a Dialog or any other kind of Window you would set this flag WindowManager.LayoutParams.TYPE_SYSTEM_ALERT. So for a Dialog it would look like this:
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
Yes, it will be able to intercept touch events. System alerts, like a low battery warning, always open on top of all other applications, so whatever Window you pop up will take focus, etc. Based on what you want to do with this, I'd imagine you could do something like: pop up a Dialog (as a system level alert) which needs a password to make it go away.
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");
}