Android 使用SensorEvent增加和减少动画和声音

Android 使用SensorEvent增加和减少动画和声音,android,Android,我试图找出当Android Studio中的emf传感器上升/下降时,如何在SensorEvent中增加/减少动画的持续时间以及声音,以下是我迄今为止所做的: public class MainActivity extends AppCompatActivity implements SensorEventListener { TextView pkeEMF; private static SensorManager sensorManager; private Sensor emfSensor

我试图找出当Android Studio中的emf传感器上升/下降时,如何在
SensorEvent
中增加/减少动画的持续时间以及声音,以下是我迄今为止所做的:

public class MainActivity extends AppCompatActivity implements SensorEventListener {
TextView pkeEMF;
private static SensorManager sensorManager;
private Sensor emfSensor;
MediaPlayer mpPKE1;
ImageView animationView;
AnimationDrawable pkeAnimation;
AnimationSound animationSound;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    pkeEMF = (TextView)findViewById(R.id.pkeEMF);
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    emfSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    mpPKE1 = new MediaPlayer();
    mpPKE1 = MediaPlayer.create(this, R.raw.pke_running_loop);
    mpPKE1.setLooping(true);
    mpPKE1.start();
    animationView = (ImageView)findViewById(R.id.pkeDot);
    animationView.setBackgroundResource(R.drawable.pkeamimation);
    pkeAnimation = (AnimationDrawable)animationView.getBackground();
    pkeAnimation.start();
    animationSound = new AnimationSound(this, R.raw.pke_beep_sound);
    animationSound.startSound();
}

public void showAnimation(View view) {
    Intent intent = new Intent(this,AnimationSound.class);
    startActivity(intent);
}

@Override
protected void onResume() {
    super.onResume();
    if (emfSensor != null) {
        sensorManager.registerListener(this, emfSensor, SensorManager.SENSOR_DELAY_NORMAL);
    } else {
        Toast.makeText(this, "Not Supported", Toast.LENGTH_SHORT).show();
        finish();
    }
}

@Override
protected void onPause() {
    super.onPause();
    sensorManager.unregisterListener(this);
}

@Override
public void onSensorChanged(SensorEvent event) {
    float azimuth = Math.round(event.values[0]);
    float pitch = Math.round(event.values[1]);
    float roll = Math.round(event.values[2]);
    double tesla = Math.sqrt((azimuth * azimuth) + (pitch * pitch) + (roll * roll));
    String text = String.format("%.1f", tesla);
    pkeEMF.setText(text + "μT");
}

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {

}
}
我该怎么做