First of all, the problem posed is insoluble - a phone that sits perfectly on a parked car (or, for that matter, works at a constant speed) is completely indistinguishable from one sitting on a table if you limit yourself to the accelerator readings.
For heuristics, I just went and wrote down samples and then selected detection algorithms. I assume that the characteristics for (urban) traffic will be attacks of almost constant acceleration for several seconds, up to 10-20 m / s, and some more sharp braking around the same full speed. I donβt think that you can integrate the accelerometer readings well enough to accurately track something like a car accelerating smoothly to speed on a cruise, staying there for an hour, and then rolling for a long time.
What are you trying to achieve?
source share