I am developing an Android application for the deaf and blind using the accessibility service
Need to disable the touch screen, because android app is controlled through a third-party device
I tried to add a view to WindowManager and disable everything there (FLAG_NOT_FOCUSABLE, FLAG_NOT_TOUCHABLE), but as far as I understand, it disabled the touch screen only in this view, but not at all
I can request any type of permission except the root
EDIT:
Due to Android security, disabling the touchscreen is not possible without root, but you can use Proximity Sensor to disable touchscreen until first power button pressure
Congratulations and good will for you are working for a good cause.
Not sure exactly how to do this but One way is to create a full screen activity - hide navigation bar and soft navigation buttons also -- please refer this documentation
And 2. override onBackPressed and never allow it to call super.onBackPressed() or relaunch your app in OnPause() method.
Hope this helps somewhat.
Related
Recently Android Wear introduced gestures so the user can navigate between apps/notifications without using their finger.
I already had a working app but that kept being removed from the screen due to these gestures. I tried it with an app made by Google itself (Googlesamples-JumpingJack) This has the same problem.
The purpose of these app is to move. But these cause the gestures to trigger. How can I disable these as long as my app is on, so that the Activity stays on the foreground?
As far as my understanding goes, you can (only?) disable gestures within the settings menu of the watch. I myself am struggling with disabling one or two specific gestures and so far found you can enable or disable them all. Haven't found anything on how to do this within your code, rather than within the settings.
I'm working on an existing Android application for medical purposes.
The back button and home button should be disabled.
With the existing code, the back button is disabled.
For disabling the home button they used onAttachedWindow with LayoutParams TYPE KEYGUARD,
but this security hole is fixed since 4.0.
I tried a lot of similar questions, but none worked out for me.
What is the way to get this done these days?
Also, hiding the status bar on tablet (where the home & back button live) would do the trick,
so any suggestions there are equally helpful!
Update: also, free third party apps that do the hiding trick are okay!
This sounds like a kiosk or dedicated use kinda thing, yes? You want your app to "own" the tablet and prevent other usage? I did this for an app whose sole purpose was to act as a remote control for a custom device. Basically I created two apps, a "custom launcher" app and the app that did the remote control. It's probably possible to integrate the two, but I wanted to support both dedicated and non-dedicated use. Note that I gave the launcher app a password-protected way to access settings so that I could recover the tablet at any time.
You can find a number of tutorials that will guide you through creating a custom launcher, just strip out all the stuff that makes it a generic launcher and replace it with an image button or similar that launches the actual app, or replace the launcher activity with your main app activity. Warning: I never figured out how to remove the launcher except by going into the settings.
As for hiding the system bar (notifications and status icons at the top of the screen), you'll want to use a full-screen theme like #android:style/Theme.NoTitleBar.Fullscreen.
As for hiding the home button I took this approach:
View main_layout = this.findViewById(android.R.id.content).getRootView();
main_layout.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
Unfortunately the STATUS_BAR_HIDDEN flag is deprecated now, but I think some of the other options would have the same effect. Regardless, the best you can achieve within Android's intended use is to temporarily hide the navigation buttons (home and back). A tap on the screen will bring them back.
A few users have been asking me Android lock screen widgets for my app - I believe they want a widget that stays on their lock screens and allows them to interact with the app.
I haven't been able to find any official documentation for this - the only thing I found was apps that will take home screen widgets and put them on the lock screen for you.
Any clues on where I learn more about building true lock-screen widgets?
Lock screen interaction is difficult. Android allows basic operations with two window flags (FLAG_SHOW_WHEN_LOCKED and FLAG_DISMISS_KEYGUARD). FLAG_SHOW_WHEN_LOCKED works pretty consistently in that it will show on top of the lock screen even when security is enabled (the security isn't bypassed, you can't switch to another non-FLAG_SHOW_WHEN_LOCKED window).
If you're just doing something temporary, like while music is playing or similar, you'll probably mostly be okay. If you're trying to create a custom lock screen then there's a lot of unusual interactions on all the different android platforms. ("Help! I can't turn off my alarm without rebooting my HTC phone").
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html
FLAG_SHOW_WHEN_LOCKED
Window flag: special flag to let windows be shown when the screen is
locked.
FLAG_DISMISS_KEYGUARD
Window flag:
when set the window will cause the keyguard to be
dismissed, only if it is not a secure
lock keyguard. Because such a keyguard
is not needed for security, it will
never re-appear if the user navigates
to another window (in contrast to
FLAG_SHOW_WHEN_LOCKED, which will only
temporarily hide both secure and
non-secure keyguards but ensure they
reappear when the user moves to
another UI that doesn't hide them). If
the keyguard is currently active and
is secure (requires an unlock pattern)
than the user will still need to
confirm it before seeing this window,
unless FLAG_SHOW_WHEN_LOCKED has also
been set.
Constant Value: 4194304 (0x00400000)
Official Lock screen widget document is here
I had to implement a lock screen widget for my project. In the process, I accumulated a couple of resources.
If you have an app that you want to put on the lock screen, first make it an appwidget. You can use the AppWidget class to do this.
Now, use the AppWidgetHost class from the Android API to make your lock screen a host for the widgets. I don't know how to do this part, but there are some existing implementations like mylockandroid (links below).
Resources
http://code.google.com/p/mylockforandroid/
(NB This code is for older versions of Android. Android 4.2 and up has built in lockscreen widget support)
http://mylockandroid.blogspot.com/2010/03/widget-lockscreen-beta-11-r2.html
I was hoping to make an app which dimmed the soft buttons to dots on the Galaxy Nexus, using the code from this answer. For completeness, this is the code:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
Here's the question, is it possible for the app to make this setting system-wide rather than just while the app has focus? So ideally the app would run in the background and would keep View.SYSTEM_UI_FLAG_LOW_PROFILE as the default as long as it's running, for any and every app that you open (unless that app specifically overrides it, I suppose). Is this possible or does this fall outside the realm of what an Android app has permission to do?
A sample use case is this: I use the "Screen Filter" app to reduce brightness a lot for nighttime ebook reading or misc app usage, but the soft buttons are still very bright and distracting, so I wanted to make an app that would dim the soft buttons system-wide while running (like how "Screen Brightness" reduces screen brightness system-wide while running) so this wouldn't be a problem.
As CommonsWare states, it's not possible for an application to change this setting. It's an Activity based setting, that must be set for every single Activity, if you want to make it fullscreen, hide the soft keys, etc.
It's also worth pointing out that you should probably refrain from using it in all your application activities. It's really only meant for games, video players and other applications that need to enter this "low profile" state.
Feel free to accept CommonsWare's answer - I just thought I'd give you a bit of background info on the subject.
is it possible for the app to make this setting system-wide rather than just while the app has focus?
No.
Let me begin by saying that, yes, I know that the stock Android lock screen can not be programatically replaced without rooting.
Now that that's over with, I want to make an app that contains a custom 'lock' mechanism. There are apps out there that emulate this functionality, namely LockGo. This allows a user to view information from widgets on a 'lock screen' and emulates the slide-to-unlock functionality (or whack-a-mole if the user wants to install that plugin).
Does anyone know what mechanism or Android API functionality they may have used to do this? Is it as simple as hooking into the power button to launch an activity, such as in the link below?
How to hook into the Power button in Android?
Any insight to this would be appreciated.
I've found out while researching this that, while there is currently no way to replace the stock security or keyguard lock (which I knew), it is possible to show an Activity on top of the lock using the following code in the setup for that Activity:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
This can be used with any logic needed to create a faux lock to show screens on top of the system lock(s), though the lock will still be in tact and the user will need to enter the lock to get into the device.