简体   繁体   English

如何在驾驶时检测手机的移动?

[英]How to detect the movement of a phone while driving?

We need to track the phone is in the drive mode without using gps.我们需要在不使用 GPS 的情况下跟踪手机处于驱动模式。 We have tried with accelerometer, but it happen only when the phone is in motion.我们尝试过使用加速度计,但只有在手机处于运动状态时才会发生。

Have you tried Significant Motion Sensor The significant motion sensor triggers an event each time significant motion is detected and then it disables itself.您是否尝试过着运动传感器每次检测到显着运动时,显着运动传感器都会触发一个事件,然后它会自行禁用。 A significant motion is a motion that might lead to a change in the user's location;显着运动是可能导致用户位置发生变化的运动; for example walking, biking, or sitting in a moving car.例如步行、骑自行车或坐在行驶的汽车中。

private SensorManager mSensorManager;
private Sensor mSensor;
private TriggerEventListener mTriggerEventListener;

mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION);

mTriggerEventListener = new TriggerEventListener() {
    @Override
    public void onTrigger(TriggerEvent event) {
        // Do work
    }
};

mSensorManager.requestTriggerSensor(mTriggerEventListener, mSensor);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM