Receiving call / Proximity Sensor - android

I am developing an App where I can receive call when mobile is brought near to ear, I have done that, now problem is call is received even when something come close to sensor inside my pocket. How can I resolve this issue?

To resolve this issue, you have to check at what angle the device is rotated in x,y,z direction before taking a call,(generally in a 'L' shape from pocket to ear) like the angle movements made when the device is lifted up to the ear.Then you will be able to distinguish between a call and device in pocket.

Related

Android Tap Device Sensor

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.

How to prevent proximity sensor from sleeping when the screen is off?

I am trying to make an application to switch on the screen when the hand is placed close to proximity sensor. However, the proximity sensor shuts down as soon as the screen is switched off. How do I prevent this?
You should write a service that registers for sensor input and uses onSensorChanged() . This way you can still listen to the event when the screen is turned off and the activity is paused.
However in Marshmallow and Nougat you have doze mode, which means the service will most probably stop running after the screen is off for a long time. I think they didn't specify behaviour for sensor change in their documentation, I'd love to hear what happens.

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.

Android - how to detect the red button in the touch screen was pressed during a call?

I would like to know if there is the possibility that my APP can notice when I clicked the red button (accidentally or not) to end a call. I have an APP running in background that can track the incoming number of the phone at the moment that I receive a call and while doing the call.
As the "red button" to end a call is not a hardware button in the touch screen phones, I'm struggling trying to know how to detect when I pressed that button. And I'm starting to think that is not really possible.
I have searched and I found that there are ways to know the position that your fingers are touching in the screen while running your APP, (I don't know if this is possible when your APP is running in background) but as every android phone has a different shape and form of hanging up a phone call this is not a possible solution for my problem.
You can find out when the user hangs up a phone by implementing a BroadCast Receiver listening to phone state. When the state becomes Idle after either ringing state or offhook state, you can get to know the call has ended. If you just want to know when the call ends this method would work fine.

Categories

Resources