Android Tap Device Sensor - android

is there a sensor in android to detect a tap on the device? I have a service and I want to detect when the user touches the phone. He can touch(tap) the screen, back or any other part of the device and it will trigger a function within my service. Is that possible? For example, if I have the device in my pocket, and I want my service to call a certain function when the user tap the phone from outside his pocket. Thanks.

You can use the accelerometer. The accelerometer detects a force on the device, and a tap would cause a force. The trick would be filtering out other forces, such as bouncing when walking.

Related

How to detect user interaction with phone in flutter?

Is there any way to detect user interaction/activity with the phone in flutter?
I want to know which app the user is using or if the user is using his phone or not. I just want to know if the user's phone is in active state or not.
Yes, I know I can use motion sensors like Gyroscope and all but is there any other way to detect phone activity in flutter?
The idea is my app will be running in the background and it will track user interaction with the phone.
If the user is using his phone like playing game, watching video or any other activity then it will show me that phone/user is active.
All I found on the internet is to track activity like walking, running motion activity.
Is there any other way to track phone activeness?

How to simulate android sensor events?

It's possible to simulate, for instance, events for android accelerometer?
Imagine the following scenario:
I have an app that at some point, if detect a X value from accelerometer, show a dialog with a question to the UI.
I want to make a test for it. To do so, I want to simulate a shake with that X value programatically, and check if the dialog appears.
I already know Sensor Simulator, but there is a way to send a value for accelerometer or other sensor and receive that changes with SensorEventListener?
Thanks in advance,
It's impossible. Because sensor event is triggered by hardware, android system get the data from hardware and don't provide interface to change the data or to trigger an sensor event. So we can't simulate a sensor event programatically. Using Sensor Simulator, or you can change the source code of android framework.

How to detect when Android phone is gone idle

I have service running in background whose job is to detect whenever phone is IDLE for more than certain time then show a popup message with an Image.
I could not find how do I detect that phone is in idle state now.
UPDATE
IDLEness is represented by following three scenarios
1) User inactivity
2) Screen goes off
3) sensors: gyroscope (x,y,z) and accelerometer remains 0 for a defined amount of time.
thanks
leo
1) User has not interacted with phone for certain time
There is no means for you to determine this.
2) Phone screen goes off when not used.
Listen for ACTION_SCREEN_OFF broadcasts.

how to detect shake event when my phone is in lock state

I read this unable to detect shake event when my phones screen is off in android article. But this question is differ from this.
I created an application which speak (using TextToSpeach API) time when I shake device. For that I have created a "Service" in which "ShakeListener" was registered. While I shake device, it will speak current time.
But this works fine while my device is "ON". When I lock my device, it stops working. Can any one elaborate what is the problem behind?
I think the problem here is that when you lock the device, it goes to sleep mode. And your ShakeListener doesn't receive shake events. The best way to implement what you want would be to register broadcast receiver to receive shake events. But as I know, android doesn't provide such broadcast. Another solution is to acuire a partial WakeLock. It'll prevent android from sleep. But of course it'll cause battery issues. Also take a look on this thread: Android accelerometer not working when screen is turned off
Probably you can not receive this notification until you patch some kernel implementation. Android doesn't broadcast such notification.

How to detect backlight is on?

My application requires resource and drains a battery when it is working. So, I want to know the way that user is not available on the phone.
Is there a way to use the built in power save mode on the blackberry to where if the screen dims to suspend the application works active and when the user wakes the device back up with a keypress or trackball movement to resume the application works active?
Thanks in advance.
Is there a way to use the built in
power save mode on the blackberry to
where if the screen dims to suspend
the application works active and when
the user wakes the device back up with
a keypress or trackball movement to
resume the application works active?
This happens automatically, with no code changes required. Unless something is holding a WakeLock, the CPU will turn off sometime after the screen goes dark. The CPU will turn back on when the user presses the power button.

Categories

Resources