Reputation: 171
In my app i use a receiver to receive the media button clicks of a bluetooth headset. When i log the whole KeyEvent i get the following log:
E/KeyEvent: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_MEDIA_PLAY, scanCode=200, metaState=0, flags=0x8, repeatCount=0, eventTime=35925738, downTime=35925707, deviceId=9, source=0x101 }
In the end of this line you can see that I get a value for the downTime. Sadly and here also comes my problem i do only get a downtime when i connect my bluetooth headset with devices with an Android Version < than Android Oreo. On Devices with Android Oreo or Android Pie i always get
downTime=0
Does someone know why this is happening or why they changed it? And does somebody know how it is possible to get a Downtime for devices with Android Oreo and higher?
Many thanks in advance and greetings! :)
Upvotes: 2
Views: 491
Reputation: 2331
To calculate the total Downtime regarding KeyEvent
use:
event.getEventTime() - event.getDownTime()
The returned value is in milliseconds
More info
Upvotes: -1