Skip to content

Instantly share code, notes, and snippets.

View navyifanr's full-sized avatar

cfanr navyifanr

View GitHub Profile
@hiwanz
hiwanz / ShakeListener.java
Last active July 12, 2016 06:17
手机摇一摇类,调用代码: ShakeListener shakeListener = new ShakeListener(this); shakeListener.setOnShakeListener(new ShakeListener.OnShakeListener() { //调用setOnShakeListener方法进行监听,摇晃手机输出信息 public void onShake() { Log.v("debuginfo","shakeing"); } });
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
public class ShakeListener implements SensorEventListener {
//速度阈值,当摇晃速度达到这值后产生作用
private static final int SPEED_SHRESHOLD = 2500;