This app was mentioned in 8 comments, with an average of 1.38 upvotes
RescueTime can do that. You can pull data from the API for use in other projects. https://play.google.com/store/apps/details?id=com.rescuetime.android
There are several others that also can do that. SmarterTime is another one that's involved in QS, and I'd assume would also be easy to get data out of. I'm biased because I work for RescueTime. :)
RescueTime helps to track how long you spend on each app either on your phone or computer.