Post Reply

keycode_headsethook "not working"

13th May 2014, 10:50 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
5 posts
Join Date:Joined: Dec 2008
Hi!

I've made a simple app that needs to catch mic button click from wired headset, and I tried to implement that via simple onKeyDown function in activity, and also with broadcastreciever, but app doesn't react on click. Or to be precise it doesn't react on some generic android phone with android 4.2, while working perfecty fine on ZTE Blade III. It does however react on other keys like Volume Up/Down. I was thinkg that maybe builtin apps have even greater priorty then my app, but don't know hot to check that, and more importantly how to prevent that, (priority of 100000 didin't help) . Also to mention that phone is registering button for recieve call, so it doesn't look like it's a hw problem.
14th May 2014, 09:54 PM   |  #2  
SimplicityApks's Avatar
Senior Member
Flag Aachen
Thanks Meter: 330
 
328 posts
Join Date:Joined: May 2013
Quote:
Originally Posted by dkovacev

Hi!

I've made a simple app that needs to catch mic button click from wired headset, and I tried to implement that via simple onKeyDown function in activity, and also with broadcastreciever, but app doesn't react on click. Or to be precise it doesn't react on some generic android phone with android 4.2, while working perfecty fine on ZTE Blade III. It does however react on other keys like Volume Up/Down. I was thinkg that maybe builtin apps have even greater priorty then my app, but don't know hot to check that, and more importantly how to prevent that, (priority of 100000 didin't help) . Also to mention that phone is registering button for recieve call, so it doesn't look like it's a hw problem.

Could you show us your onKeyDown implementation? That would certainly help. I'm guessing you have a certain keyCode you are checking in that method, it could be as simple as that the 4.2 device just has it configured differently so the keycode passed to onKeyDown is different. Just put a Log.d("myApp", "Pressed key with code: "+keycode); in there and see if you get any logs.

If the whole method isn't called, it might be that some view in the activity is consuming the key event, as indicated in the documantation. It is also possible that the onKeyDown isn't called at all for you keycode.
14th May 2014, 10:54 PM   |  #3  
OP Junior Member
Thanks Meter: 0
 
5 posts
Join Date:Joined: Dec 2008
Thanks for the interest, code is simple

Code:
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    	
    	Toast.makeText( this, "BUTTON pressed!", Toast.LENGTH_SHORT).show(); 
    	
    	String myStr = ""; 
        if ((keyCode == KeyEvent.ACTION_DOWN)){
        	Toast.makeText( this, "BUTTON down", Toast.LENGTH_SHORT).show(); 
        }

        if ((keyCode == KeyEvent.KEYCODE_HEADSETHOOK)){
        	Toast.makeText( this, "BUTTON Headset key Down!", Toast.LENGTH_SHORT).show(); 
        }

        if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)){
        	Toast.makeText( this, "BUTTON volume Down!", Toast.LENGTH_SHORT).show(); 
        }
        ...
As you can guess, nothing happens even before 'if statements', VOLUME_UP works fine, same thing happens in onKeyUp function.
I also tried with broadcast recievers, copy/pasted sample from SDK (Random Music Player) that works with Broadcast Recievers, still nothing.

Button itself, works for recieving calls, but nowhere else, I read somewhere that with JellyBean Google introduced Media control with mic button for play/pause functionality in music player, but it won't work for me, when I press buttton during playback, volume is up, while holding, and that's it.

And still, same code works perfectly fine on 4.0.4, maybe it's something with this particular 4.2.2 that prevents me from capturing key, but don't know how and where to look about it
15th May 2014, 10:09 AM   |  #4  
SimplicityApks's Avatar
Senior Member
Flag Aachen
Thanks Meter: 330
 
328 posts
Join Date:Joined: May 2013
Quote:
Originally Posted by dkovacev

Thanks for the interest, code is simple

Code:
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    	
    	Toast.makeText( this, "BUTTON pressed!", Toast.LENGTH_SHORT).show(); 
    	
    	String myStr = ""; 
        if ((keyCode == KeyEvent.ACTION_DOWN)){
        	Toast.makeText( this, "BUTTON down", Toast.LENGTH_SHORT).show(); 
        }

        if ((keyCode == KeyEvent.KEYCODE_HEADSETHOOK)){
        	Toast.makeText( this, "BUTTON Headset key Down!", Toast.LENGTH_SHORT).show(); 
        }

        if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)){
        	Toast.makeText( this, "BUTTON volume Down!", Toast.LENGTH_SHORT).show(); 
        }
        ...
As you can guess, nothing happens even before 'if statements', VOLUME_UP works fine, same thing happens in onKeyUp function.
I also tried with broadcast recievers, copy/pasted sample from SDK (Random Music Player) that works with Broadcast Recievers, still nothing.

Button itself, works for recieving calls, but nowhere else, I read somewhere that with JellyBean Google introduced Media control with mic button for play/pause functionality in music player, but it won't work for me, when I press buttton during playback, volume is up, while holding, and that's it.

And still, same code works perfectly fine on 4.0.4, maybe it's something with this particular 4.2.2 that prevents me from capturing key, but don't know how and where to look about it

Ah ok, so it doesn't even get called :/ Then I would probably try to use the broadcastReceiver again, did you do it like this (its a different question but the code looks fine)? I think it's better to use a receiver anyway since it is not connected to the activity or the views in it.
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Java for Android App Development by ThreadRank