How can I make android react as in a call and the proximity sensor is triggered?

I have an application which makes VoIp call. During those call, I would like the screen to react exactly as it does during a normal call. That is, i want the screen to disable all events and turn off when the user triggers the proximity sensor. Of course, when the user moves away his ear from the phone, I want the phone to turn the screen on and enable back all events. I tried before to turn off and on the screen myself. Never worked. So I thought i'd used this solution.

Answers


There is a similar question I found which gives some great info on the Proximity Sensor using samples from the Android Phone app.

android: turn off screen when close to face


Here is the code which may help you ..this demonstrate how we can access proximity sensor using SensorManager Class,here the proximity sensor will triggered an it calls a method which changes an image view you can try your code on that method...., get the Whole Source code here

public class MainActivity extends Activity {
SensorManager sm;
Sensor ProximitySensor;
boolean state=true;
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    txstate= (TextView) findViewById(R.id.txstate);
    sm = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
    ProximitySensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    sm.registerListener(proximitySensorEventListener,  ProximitySensor, SensorManager.SENSOR_DELAY_FASTEST);


}
SensorEventListener proximitySensorEventListener = new SensorEventListener()
{   
  @Override
  public void onAccuracyChanged(Sensor sensor, int accuracy) 
  {

  }
@Override
public void onSensorChanged(SensorEvent event) 
{
if(event.sensor.getType()==Sensor.TYPE_PROXIMITY)


    {if((int)(event.values[0])==1)

        {

                    call();
        }
    }

}

private void call() 

{
        ImageView im = (ImageView) findViewById(R.id.imageView1);
        if(state)
        {
            state =false;                
            im.setImageResource(R.drawable.smile);                   
        }
        else 
        {
            state=true;              
            im.setImageResource(R.drawable.sad);             
        }
    }
};
}

Need Your Help

How to call overloaded c# functions which the only difference is parameter passed by ref or not in c++/cli

c# c++-cli overloading tracking-reference

I've a C# class library with overloaded methods, and one method has a ref parameter and the other has a value parameter. I can call these methods in C#, but I can't get it right in C++/CLI. It's se...

Post DbGeography data type in odata v4 api

asp.net-web-api odata geo odata-v4

What i receive from a DbGeography data type is in Location.