Created
August 30, 2018 22:24
-
-
Save ziginsider/809a7ba4dbebba8f22608da43c9625c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.github.ziginsider.mediabuttons | |
import android.content.BroadcastReceiver | |
import android.content.Context | |
import android.content.Intent | |
import android.util.Log | |
import android.view.KeyEvent | |
class UiReceiver : BroadcastReceiver() { | |
override fun onReceive(context: Context?, intent: Intent?) { | |
Log.d("TAG","[ onReceive ]") | |
val trappedKeyEvent = intent?.extras?.get(Intent.EXTRA_KEY_EVENT) as? KeyEvent | |
val keyKode = trappedKeyEvent?.keyCode | |
Log.d("TAG", "[ keyKode = $keyKode ]") | |
when (keyKode) { | |
KeyEvent.KEYCODE_MEDIA_NEXT -> Log.d("TAG", "[ next track ]") | |
KeyEvent.KEYCODE_MEDIA_PREVIOUS -> Log.d("TAG", "[ previous track ]") | |
KeyEvent.KEYCODE_MEDIA_PLAY -> Log.d("TAG", "[ play ]") | |
KeyEvent.KEYCODE_MEDIA_PAUSE -> Log.d("TAG", "[ pause ]") | |
KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE -> Log.d("TAG", "[ play and pause ]") | |
KeyEvent.KEYCODE_MEDIA_STOP -> Log.d("TAG", "[ stop ]") | |
else -> Log.d("TAG", "[ something unknown ]") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment