1

I am trying to create an android application to find the phone moving direction with Text to speech.There is a lot of problems with this.ie,it working some what,and i am not getting accurate movement.this is my code

    @Override
public void onSensorChanged(SensorEvent event) {
    Sensor sensor = event.sensor;
     float [] values = event.values;
     synchronized (this) {
             Log.d(tag, "onSensorChanged: " + sensor + ", x: " + 
                             values[0] + ", y: " + values[1] + ", z: " + values[2]);
     if (sensor.getType() == Sensor.TYPE_ACCELEROMETER ) {
         x.setText("x"+ values[0]);
         y.setText("y"+ values[1]);
         z.setText("z"+ values[2]);

         xa=(int)values[0];// this part of code is only test to see int x and y on Activity
         ya=(int)values[1];

         ball.scrollBy(xa, ya);
         a=Integer.toString(xa);
         b=Integer.toString(ya);
         ball.scrollBy(xa, ya);
         xat.setText(a);
         yat.setText(b);

        if (trigL || trigD || trigR || trigU ) {

             int ttt = TextToSpeech.QUEUE_FLUSH;

            final long ACCEL_SENSOR_DELAY = 100; 
            long lastAccelSensorChange = 0;
            long now = System.currentTimeMillis();
            if ((now-ACCEL_SENSOR_DELAY) > lastAccelSensorChange) {
                lastAccelSensorChange = now;
              ttt = TextToSpeech.QUEUE_FLUSH;
               sensore.registerListener(MainActivity.this, accelerometer,
             trigL = false;
                 trigR = false;
                 trigU = false;
                 trigD = false;

        }
            }

         if (values[0] < -6) {
             trigL = true;
            if(tts.isSpeaking())
            {    
                 return;
            }
            else

            tts.speak("Move Left", TextToSpeech.QUEUE_FLUSH, null);

            values[0]=0;
            values[1]=0;
            return;

        } else if (values[0] > 6) {
            trigR = true;
            if(tts.isSpeaking())
            {
                 return;    
            }
            else
            tts.speak("Move Right", TextToSpeech.QUEUE_FLUSH, null);
            values[0]=0;
            values[1]=0;

            return;
        } 

        else  if (values[1] < -6) {

            trigD = true;
            if(tts.isSpeaking())
            {
                 return;
            }
            else

            tts.speak("Move Down", TextToSpeech.QUEUE_FLUSH, null);
            values[1]=0;
            values[0]=0;

            return;
        } else if (values[1] > 6) {

            trigU = true;
            if(tts.isSpeaking())
            {

                 return;

            }
            else        
            tts.speak("Move Up", TextToSpeech.QUEUE_FLUSH, null);
            values[1]=0;
            values[0]=0;

            return;
        }
     }
     }

}

I am searching for last 2 weeks. Any suggestions can be help full for me.

Sree
  • 3,136
  • 2
  • 31
  • 39
  • You also need to register for Sensor.TYPE_MAGNETIC_FIELD and use these sensor values to calculate the tilt angles. – Hoan Nguyen Feb 27 '13 at 18:38
  • thanks for your replay and can u able to add some link or code which help me to calculate the tilt angles. – Sree Feb 28 '13 at 04:41
  • You can see my comment at http://stackoverflow.com/questions/15109073/how-to-adequatly-replace-sensor-type-orientation-which-is-now-deprecated and write the code for it. – Hoan Nguyen Feb 28 '13 at 04:49
  • @HoanNguyen Can you help me out on this [question](http://stackoverflow.com/questions/34997669/android-acceleration-down-smash) please? – Skizo-ozᴉʞS ツ Jan 26 '16 at 00:45

0 Answers0