How do I respond to the KEYCODE_HEADSETHOOK?
up vote
0
down vote
favorite
I want a easy app that does nothing but respond to the key KEYCODE_HEADSETHOOK, and when it get it, it make a Toast.
After Android 5.0 (21), I see many pages that do this, but it seems that they did not work well.
I tried MediaSessionCompat, AudioManager, MediaSession.Callback, MyReceiver extends BroadcastReceiver, but none of them works.
The log says,
dispatchMediaKeyEvent:com.**.**.my true KeyEvent { action=ACTION_UP, keyCode=KEYCODE_HEADSETHOOK, scanCode=226, metaState=0, flags=0x8, repeatCount=0, eventTime=14529808, downTime=14529808, deviceId=1, source=0x101 } false java.lang.Throwable
and then
Sending KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_HEADSETHOOK, scanCode=226, metaState=0, flags=0x8, repeatCount=0, eventTime=9767039, downTime=9767039, deviceId=1, source=0x101 } to the last known PendingIntent PendingIntent{7c7b120: PendingIntentRecord{6be5ad9 tv.**.** broadcastIntent}}
I do not know where I was wrong.
android media-buttons
add a comment |
up vote
0
down vote
favorite
I want a easy app that does nothing but respond to the key KEYCODE_HEADSETHOOK, and when it get it, it make a Toast.
After Android 5.0 (21), I see many pages that do this, but it seems that they did not work well.
I tried MediaSessionCompat, AudioManager, MediaSession.Callback, MyReceiver extends BroadcastReceiver, but none of them works.
The log says,
dispatchMediaKeyEvent:com.**.**.my true KeyEvent { action=ACTION_UP, keyCode=KEYCODE_HEADSETHOOK, scanCode=226, metaState=0, flags=0x8, repeatCount=0, eventTime=14529808, downTime=14529808, deviceId=1, source=0x101 } false java.lang.Throwable
and then
Sending KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_HEADSETHOOK, scanCode=226, metaState=0, flags=0x8, repeatCount=0, eventTime=9767039, downTime=9767039, deviceId=1, source=0x101 } to the last known PendingIntent PendingIntent{7c7b120: PendingIntentRecord{6be5ad9 tv.**.** broadcastIntent}}
I do not know where I was wrong.
android media-buttons
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want a easy app that does nothing but respond to the key KEYCODE_HEADSETHOOK, and when it get it, it make a Toast.
After Android 5.0 (21), I see many pages that do this, but it seems that they did not work well.
I tried MediaSessionCompat, AudioManager, MediaSession.Callback, MyReceiver extends BroadcastReceiver, but none of them works.
The log says,
dispatchMediaKeyEvent:com.**.**.my true KeyEvent { action=ACTION_UP, keyCode=KEYCODE_HEADSETHOOK, scanCode=226, metaState=0, flags=0x8, repeatCount=0, eventTime=14529808, downTime=14529808, deviceId=1, source=0x101 } false java.lang.Throwable
and then
Sending KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_HEADSETHOOK, scanCode=226, metaState=0, flags=0x8, repeatCount=0, eventTime=9767039, downTime=9767039, deviceId=1, source=0x101 } to the last known PendingIntent PendingIntent{7c7b120: PendingIntentRecord{6be5ad9 tv.**.** broadcastIntent}}
I do not know where I was wrong.
android media-buttons
I want a easy app that does nothing but respond to the key KEYCODE_HEADSETHOOK, and when it get it, it make a Toast.
After Android 5.0 (21), I see many pages that do this, but it seems that they did not work well.
I tried MediaSessionCompat, AudioManager, MediaSession.Callback, MyReceiver extends BroadcastReceiver, but none of them works.
The log says,
dispatchMediaKeyEvent:com.**.**.my true KeyEvent { action=ACTION_UP, keyCode=KEYCODE_HEADSETHOOK, scanCode=226, metaState=0, flags=0x8, repeatCount=0, eventTime=14529808, downTime=14529808, deviceId=1, source=0x101 } false java.lang.Throwable
and then
Sending KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_HEADSETHOOK, scanCode=226, metaState=0, flags=0x8, repeatCount=0, eventTime=9767039, downTime=9767039, deviceId=1, source=0x101 } to the last known PendingIntent PendingIntent{7c7b120: PendingIntentRecord{6be5ad9 tv.**.** broadcastIntent}}
I do not know where I was wrong.
android media-buttons
android media-buttons
asked Nov 8 at 3:01
chuanrui yan
11
11
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53200948%2fhow-do-i-respond-to-the-keycode-headsethook%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown