Programatically detect presence of hardware call/hang up keys
One of my clients wants a code method that returns a boolean. True if the Android phone has hardware red/green call/hang up keys and false if it does not.
Sonething like this :
public void keyFeedbackFromInput(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN
&& (event.getFlags() & KeyEvent.FLAG_VIRTUAL_HARD_KEY) != 0) {
// perform your logic here
}
}
But not in a key press event as in the code snippet above. He 开发者_如何学Pythonneeds to determine this up front if a phone has physical red/green keys or virtual ones.
Is it possible and if yes can someone provide a code sample to achieve this?
EDITED:
There is no call to get that kind of info.
You can try having a dictionary with Build.MODEL
as key.
Something like:
/* Create the dictionary */
private HashMap<String, Boolean> redGreenKeys = new HashMap<String, Boolean>();
redGreenKeys.put("Milestone", false);
public Boolean hasRedGreenButtons() {
Boolean ret = redGreenKeys.get(Build.MODEL);
if ( ret == null )
return false;
return ret;
}
精彩评论