Android enables apps to draw over other apps with android.permission.SYSTEM_ALERT_WINDOW and it's called a floating/overlaying app. For example Facebook Messenger has always visible chat bubbles at the edges of screen.
My question is: Is it possible to detect or block in Java code any app which draws over my app?
There is a View#onFilterTouchEventForSecurity() method you can override to detect if the motion event has the FLAG_WINDOW_IS_OBSCURED. This will let you know if something is drawn on top of your view.
#Override
public boolean onFilterTouchEventForSecurity(MotionEvent event) {
if ((event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) == MotionEvent.FLAG_WINDOW_IS_OBSCURED){
// show error message
return false;
}
return super.onFilterTouchEventForSecurity(event);
}
If you just want to protect your app from tap jacking due to another app drawing over your app you can add setFilterTouchesWhenObscured to your views via XML or programmatically.
Related
I have an app which uses geofire to identify if the user enters the designated boundaries and when the it is true, the user's phone will be temporarily disabled in which touch functionality will be disabled.Otherwise, it will be enabled if the user leaves the assigned boundaries.Anyone can help?It would be my pleasure to hear your thoughts.
Thank you!
If you want to disable the current activity then you can dispatchTouchEvent().
Example of using it:
private var inRange = false
#Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (!inRange)
return super.dispatchTouchEvent(ev);
return true;
}
If that's not what you are looking sorry, can you explain it a bit more?
I think you can make a service that create an transparent overlay then you disable on click for this overlay .. you can see this link for more details about this solution
How do I make my full-screen overlay remain full-screen after orientation changes?
I want to have the user use fingerprint authentication to allow them to perform an action within my app. I have already performed the necessary check, does the hardware exist, is a fingerprint registered etc when they say they would like to use fingerprint auth.
An alertdialog currently opens when it is time for the user to authenticate with their fingerprint. I'd like to know if it is actually possible to catch the fingerprint through an alertdialog as and alertdialog afaik only has positive and negative button input options.
If it is not possible to do this through an alertdialog, a point in the right direction would be much appreciated.
EDIT: Just to be clear, I don't mean using the screen as a fingerprint sensor.
You can use this FingerprintDialog library. Then it goes simply like this :
FingerprintDialog.initialize(this)
.title(R.string.title)
.message(R.string.message)
.callback(new FingerprintCallback({
#Override
public void onAuthenticationSuccess() {
// Fingerprint recognized
}
#Override
public void onAuthenticationCancel() {
// User pressed cancel button
}
}))
.show();
Otherwise, you just have to create a custom xml layout, get the view using a LayoutInflater and call setView(view) on the dialog. Google it.
This currently isn't possible. Or if it is, I really doubt it. Most touch screen phones use a capacitive touch. Which means, since our fingers conduct electricity, we disturb the electric fields infront of the phone's screen. While it does support multitouch, I really doubt it's so precise that it detects the ridges on our fingers.
You would need more of a heat sensitive touch screen. Which I don't think they use in most new generation touch screens.
So you could use this API https://developer.android.com/reference/android/hardware/fingerprint/FingerprintManager.html but only in device that contains fingerprint scan and definitely not through the screen of you device.
The App currently runs in IMMERSIVE_STICKY mode, but when user swipes from the side - OS shows menu and home/back buttons. So user can turn my app off or run some other stuff which is unacceptable. Therefore, I need to disable touchscreen device completely on android to prevent any taps and swipes.
If i cant disable it via official API, can i disable touchpad using console? Android will be rooted.
I found that my touchpad device is /sys/devices/virtual/input/input1 but still cant find where can I disable it. /power/control takes only 'on' or 'auto'.
I found other solution with xinput but on android there is no one.
I think you can override the function onTouchEvent.
private boolean touch_disabled=true;
#Override
public boolean onTouchEvent(MotionEvent e) {
if (touch_disabled){
return true;
}else {
//do something here if your touch screen is activated
}
}
public disable_touch(boolean b) {
touch_disabled=b; //function to activate or desactivate touch screen
}
I'm developing a simple app on PhoneGap for an Android set top box.
I have an image that is usable as a link. When I connect a mouse to the set top box and click the image, the link works. But when I use the remote control and select the image (I see the border around the image so I know it is selected) and I click OK button, the link does not work.
How can I use the remote buttons in the code?
This is very tricky because Google didn't feel like mapping the keys on a remote to an actual key output.
To use the setTopBox, you're going to have to figure out what key codes your Android Set Top Box is using and modify the Activity's onKeyUp event to handle it. We currently have an example of a work-around in this bug however we don't have an agreed API for exposing these buttons to Javascript yet, which is why this bug is still open.
But in short, you'd do something like this:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_UP)
{
sendJavascript("javascript:myJsMethod('UP');");
return true;
}
return super.onKeyDown(keyCode, event);
}
So I was trying to disable the screen for an app I am making for a brief period using this
#Override
public boolean onTouchEvent(MotionEvent pMotioneEvent) {
if(pMotioneEvent.getY() < TestSprite.getY()){
return false;
}else{
return true;
}
}
but this seems to have no effect. I read around and it seems like in general its a bad idea to disable the touch screen, but I'm still curious to know if there is a way.
Thanks
You could try
requestDisallowInterceptTouchEvent
If you want to check for touchevents in a certain area of your screen, you might want to put this in a View and set a touchEvent Listener to it.