Friday, February 14, 2014

android home button ineffective listening is how?


Found himself yesterday onKeydown (...) can not monitor the home button, the Internet search a bit, usually written like this:
1 First set permissions shielded Home key


2. @ Override
public void onAttachedToWindow () {
/ / TODO Auto-generated method stub
Log.d ("aeon", "onAttachedToWindow");
this.getWindow () setType (WindowManager.LayoutParams.TYPE_KEYGUARD);.
super.onAttachedToWindow ();
}
3.
@ Override
public boolean onKeyDown (int keyCode, KeyEvent event) {
/ / TODO Auto-generated method stub
Log.d ("aeon", "onKeyDown");
if (KeyEvent.KEYCODE_HOME == keyCode)
Log.d ("aeon", "home");
return super.onKeyDown (keyCode, event);
}

But the facts prove that this is not acceptable. Specifically how to listen for the home button.

Currently only found onSaveInstanceState can play the role of the listener. I test version is android4.1.

Which passing the Great God, please guide us. Thanks<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Monitor the HOME key, which does not require shielding Manifest.xml it directly inside the onKeyDown capture, captured after doing their own thing and then directly back, do not call return super.onKeyDown (keyCode, event);
The landlord can try
Reply:
cited a floor lihui_shine reply:
monitor the HOME key, which does not require shielding Manifest.xml it directly inside the onKeyDown capture, captured after dry own thing and then directly back, do not call return super.onKeyDown (keyCode, event);
The landlord can try

This time I have to deal with, did not play log, it should be understood that it is not caught.
 @ Override 
public boolean onKeyDown (int keyCode, KeyEvent event) {
/ / TODO Auto-generated method stub
Log.d ("aeon", "onKeyDown");
if (KeyEvent.KEYCODE_HOME == keyCode)
Log.d ("aeon", "home");
return super.onKeyDown (keyCode, event);

Reply:
I do not know why LZ monitor home button, if you want to handle the user presses the home button operation program to be executed, you can go to the next onUserLeaveHint () function, press the home key will be to execute the function.
Reply:
reference to the third floor hilter1949 reply:
LZ do not know why the home button to listen, if you want to handle the user presses the home button operation program to be executed, you can see Under onUserLeaveHint () function, press the home key will be to execute the function.


Xiongtai're right. Why should we listen HOEM.
Also, as far as I know, framework will provide listeners HOEM is not, because if you can listen, malicious programs to the HOME key functions can be masked.
You can try preguide, if this is something.
Reply:
You can monitor the broadcast
ACTION_CLOSE_SYSTEM_DIALOGS
To monitor the home button
Reply:
4.0 or later has been the system to intercept
Reply:
reference to the third floor hilter1949 reply:
LZ do not know why the home button to listen, if you want to handle the user presses the home button operation program to be executed, you can see Under onUserLeaveHint () function, press the home key will be to execute the function.

This does work, executed before onSaveInstanceState.
Reply:
references, 4th Floor leehong2005 reply:
Quote: references to the third floor hilter1949 reply:

I do not know why LZ monitor home button, if you want to handle the user presses the home button operation program to be executed, you can go to the next onUserLeaveHint () function, press the home key will be to execute the function.


Xiongtai're right. Why should we listen HOEM.
Also, as far as I know, framework will provide listeners HOEM is not, because if you can listen, malicious programs to the HOME key functions can be masked.
You can try preguide, if this is something.

android4.1 and 4.2 pairs home key is listening, just do not know there is no lower version.
What you say is this preguide. I am not very clear, specific points can not
Reply:
reference to the 6th floor csh159 reply:
4.0 or later system to have been intercepted

Maybe yes
Reply:
reference to the 8th floor zhangle123 reply:
Quote: references to the 4th floor leehong2005 reply:

Quote: references to the third floor hilter1949 reply:

I do not know why LZ monitor home button, if you want to handle the user presses the home button operation program to be executed, you can go to the next onUserLeaveHint () function, press the home key will be to execute the function.


Xiongtai're right. Why should we listen HOEM.
Also, as far as I know, framework will provide listeners HOEM is not, because if you can listen, malicious programs to the HOME key functions can be masked.
You can try preguide, if this is something.

android4.1 and 4.2 pairs home key is listening, just do not know there is no lower version.
What you say is this preguide. I am not very clear, specific points can not


4.1/4.2 new function may be offered it. Low version far as I know, there should not be.
Since that time, we did a project, but also need to know the home button is pressed. We then approach is to modify the underlying framework, the home press event that, send a broadcast message. Then recompile.
Of course, this APP for a common development, not as powerless to change the underlying.
Reply:
reference to the 10th floor leehong2005 reply:
Quote: references to the 8th floor zhangle123 reply:

Quote: references to the 4th floor leehong2005 reply:

Quote: references to the third floor hilter1949 reply:

I do not know why LZ monitor home button, if you want to handle the user presses the home button operation program to be executed, you can go to the next onUserLeaveHint () function, press the home key will be to execute the function.


Xiongtai're right. Why should we listen HOEM.
Also, as far as I know, framework will provide listeners HOEM is not, because if you can listen, malicious programs to the HOME key functions can be masked.
You can try preguide, if this is something.

android4.1 and 4.2 pairs home key is listening, just do not know there is no lower version.
What you say is this preguide. I am not very clear, specific points can not


4.1/4.2 new function may be offered it. Low version far as I know, there should not be.
Since that time, we did a project, but also need to know the home button is pressed. We then approach is to modify the underlying framework, the home press event that, send a broadcast message. Then recompile.
Of course, this APP for a common development, not as powerless to change the underlying.

Thank you, you are engaged in system customization?
Reply:
The brothers Hello, I recently also encountered this problem, I would like to shield the home key function, it is now able to listen to press the home button, but still directly back to the main screen, do not know how you can operate masked it?
Reply:
# 5 Building positive solution, want to completely monitor the home button in the framework layer needs to deal with.

/ Frameworks / base / policy / src / com / android / internal / policy / impl / PhoneWindowManager.java

Inside to modify private void handleLongPressOnHome () method.

No comments:

Post a Comment