Pregunta

How to auto answer to a call when accelerometer change to a specific value.

 public void onSensorChanged(SensorEvent event) {
    if (event.values[0] <1) {
       //ANSWER CODE

          //Sometext
       acceleration.setText("ANSWERED");
    }

The code from bellow is to answer to a call, but I don't want to press a button. I don't know how to convert this code to add it where is onSensorChanged:

Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
i.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP,
        KeyEvent.KEYCODE_HEADSETHOOK));
context.sendOrderedBroadcast(i, null);
¿Fue útil?

Solución

You should do something along the lines of

Intent i = new Intent(Intent.ACTION_ANSWER);
startActivity(i);

The doc for the Intent.ACTION_ANSWER is here, you might want to take a look at it. It seems it doesn't need any extras, so you may be good with this.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top