手机要是动一下,就喊话“摇摇零线,摇摇零线”,是不是比较酷,
这里实现一下手机翻转一下,播放声音的效果,
通过sensor识别到手机的运动状况,然后播放音频,
public class MainActivity extends AppCompatActivity {
MySensorEventListener sensorEventListener;
private String tag = "test9";
public class MySensorEventListener implements SensorEventListener {
private float prevY;
private float prevZ;
@Override
public void onSensorChanged(SensorEvent event) {
float[] values = event.values;
int type = event.sensor.getType();
if (type == Sensor.TYPE_ACCELEROMETER) {
float x = values[0];
float y = values[1];