title: I want to create touch event on screen in android, as magnetic field change
body: <p>I want to create a service which will run in background and create touch event on screen in android, as magnetic field change for my virtual reality glasses.</p>
  
  <p>this my code</p>
  
  <pre><code>        public void onSensorChanged(SensorEvent sensorEvent) {
              synchronized (this) {
                  if (sensorEvent.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
                      magneticX.setText( Float.toString( sensorEvent.values[0]));
                      magneticY.setText( Float.toString( sensorEvent.values[1]));
                      magneticZ.setText( Float.toString( sensorEvent.values[2]));
  
  
                      if(sensorEvent.values[0]&gt;100){
  
  
  //                      Long time = System.currentTimeMillis();
  //                       View v = getWindow().getDecorView().getRootView();
  //                       MotionEvent event = MotionEvent.obtain(time,time,0,100f ,100f, 0);
  //                       v.dispatchTouchEvent(event);
                          Process process = null;
                          try {
  
                              process = Runtime.getRuntime().exec("adb shell input tap 100 100 ");
                              ((TextView)findViewById(R.id.valMag_Msg)).setText("Magnet on Left lower corner");
                          } catch (IOException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          }
                          BufferedReader bufferedReader = new BufferedReader(
                          new InputStreamReader(process.getInputStream()));
  
                      }else{
                          ((TextView)findViewById(R.id.valMag_Msg)).setText("Normal");;                       
                      }
                  }
              }
  
          }
  </code></pre>