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
}
Related
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.
I have a Xamarin Android application with a GestureDetector. On my device (Sony Xperia S5303) and in emulators it works fine. However, on a Samsung Galaxy tablet, the OnSingleTapUp event is fired twice, even though I touch the screen just once. Since the event is checked by the OnSingleTapConfirmed, and the device behaves as if two taps were made, the following method is never called:
public bool OnSingleTapUp(MotionEvent e)
{
if (PersistentContext.LoggedPlayer.Token)
{
if (simpleOnGestureListener.OnSingleTapConfirmed(e))
{
Move(e);
}
return true;
}
return false;
}
The strange thing is, that when clicking on a button, the button method is called just once. Can anybody tell me what might cause this strange behaviour and how to avoid it?
You need to use onSingleTapConfirmed(MotionEvent event) instead. This way android makes sure it's a single tap and doesn't fire the event twice.
Edit: if you are determined to use onSingleTapUp(MotionEvent event), then you can use event.getEventTime()and if the time difference between the first and second events is less than a THRESHOLD like 200ms or something, consider it the unwanted second-time fired tap and ignore it.
Edit 2: Since I don't use Xamarin I might be totally wrong but I think you need to change your code like this: (I mean forget onSingleTapUp completely and move wyour whole code into onSingleTapConfirmed)
#Override
public boolean onSingleTapConfirmed(MotionEvent event) {
if (PersistentContext.LoggedPlayer.Token)
{
Move(e);
return true;
}
return false;
}
Hope it helps and Good Luck!
I am trying to implement some hints when a user is hovering a button or another view, I see that android have support for onHoverListener but I don't understand how it really works. However I did try to find a solution how to make a floating editText on a button hover but I didn't find any ideas.
I am thinking that hover in android is the same think with long click because you can't hover with finger without clicking the view.
OnHoverListener is only implemented in 2 specific situations: a) when a Bluetooth or USB mouse is plugged into the device, or b) on Galaxy Note devices, when the S-Pen (stylus) is hovering over the object.
In specific setups/situations this can be a very neat feature, but unfortunately, most users will never even know it exists. For your situation, you may want to implement an OnLongClickListener for showing hints/tips as that is pretty standard in Android.
This example will show a TextView or ImageView hint for 5 seconds when a long-click is initiated:
btn.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View view) {
findViewById(R.id.hint).setVisibility(View.VISIBLE);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
findViewById(R.id.hint).setVisibility(View.GONE);
}
}, 5000);
return true;
}
});
Hope this helps,
I want to add up on Aaron's answer.
Some devices with sensitive screens - Samsung S5 comes to mind - don't even need an s-pen.
Just need to hold your finger 1/2 inch over the screen and it would trigger it.
I'm new to programming for Google Glass. I really like the cards possibilities (https://glass-python-starter-demo.appspot.com/) and it's great that I can submit HTML.
Because the project I'm working on (for which I would like to use Glass) is an online platform, I would like to be able to work from the website. As I found out, I can detect (from the user agent) that Glass is being used (http://www.googleglass.gs/quick-tip-google-glass-web-browser-user-agent/)
So, now my question in two parts.
1) Can I create an Android app that's actually a 'browser without a toolbar' so that I can direct directly to a webpage, but that functions as an app so that I can have it in the menu (after: "ok Glass")?
2) Can I use voice commands in the above app?
PS:
I know this is a beginner question, but -with exception from the Glass Cards option- it's hard to find a starting point for this.
So if I understand you correctly, you want to do this following:
1) Create an app that is basically just a browser.
2) Have the link that opens be to your website where the app is actually contained.
3) Use voice commands to control this app.
All to bypass having to code in java/xml so you can code in the language you know better and then run it online, and just have one line of code creating the browser in the actual app code.
Yes, you can create an app that is just a browser.
Yes, you can have it link to your website and then have it stay there.
I think that it will be much harder for you to interact with the website. The default browser controls are tap to click, hold 2 fingers down and move your head to move "mouse" around the current screen, slide up and down to scroll.
If you want to control the app, you'd have to implement your own gesturedetector, override the default actions taken each time you do something, and then for each action send something to your website to let it know that you just did something.
You could use voice recognition for controls as well.
Either way, you'll need a gesturedetector to override the default controls for the browser if you decide to use the standard one. Here is what you'd need for that:
At the very top, you'll have
private GestureDetector gestureDetector;
Then in your onCreate method, you'll need to create your gestureDetector. I like to have a method to create it farther down. It is just cleaner that way for me.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gestureDetector = createGestureDetector(this);
}
And then the method to actually create the GestureDetector:
private GestureDetector createGestureDetector(Context context) {
GestureDetector gestureDetectorTemp = new GestureDetector(context, new GestureDetector.OnGestureListener() {
#Override
public boolean onDown(MotionEvent motionEvent) {
return false;
}
#Override
public void onShowPress(MotionEvent motionEvent) {
return false;
}
#Override
public boolean onSingleTapUp(MotionEvent motionEvent) {
//communicate to the website that you tapped, and have it handle the tap
Log.v("APP_TAG","Someone tapped me!");
return false;
}
#Override
public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent2, float distanceX, float distanceY) {
return false;
}
#Override
public void onLongPress(MotionEvent motionEvent) {
return false;
}
#Override
public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent2, float v, float v2) { //fling = a single slide
return false;
}
});
return gestureDetectorTemp;
}
Notice that each method that was overriden has a "return false" in it. The boolean you are returning represents whether or not the event is to be consumed.
In other words, if you look at onSingleTapUp, we have a Log.v that will print out "Someone tapped me!" when you tap the screen. By returning false, you are letting whatever else was going to occur based on a tao (in the case of a browser, a "click" of the mouse) occur. If you return true, nothing else will occur. The event won't be reported to the other default methods. So to nullify all of the default controls of the browser, you would just change all of the return statements there to "return true", indicating that the event was consumed and that no further action is necessary!
I hope that helped a bit. If you goal is to completely bypass the entire android coding platform and just develop in the browser and then link the app to the browser, I don't think you'll be able to do it completely just because of the nature of Glass. There is no touch screen with lots of different buttons and a keyboard, etc. You'll need to do at least some glass development to get it to work.
How can I detect whether a browser has tap highlighting? I could just scan the user agent string for "iphone", "ipad", and "android" and hope to cover most touch screen devices, but that seems rather crude. Do you know of a way to tell reliably? Or any other ideas?
I want to disable my CSS :hover effects if the browser has tap highlighting (having both at the same time is quite disconcerting). In my case that's much preferable to disabling the tap highlighting.
Thanks for your time and I'd appreciate any ideas you might have!
You can use the following code snippet to detect touch screen devices:
function is_touch_device() {
try {
document.createEvent("TouchEvent");
return true;
} catch (e) {
return false;
}
}