4

In Android application is it possible that when I press my mobile *(star) button(not widget button) then I can perform any particular events in my application? If it's possible, then how may I achieve it?

Piotr Chojnacki
  • 6,837
  • 5
  • 34
  • 65
amardeep
  • 492
  • 4
  • 19

2 Answers2

1

If you mean the * key from your hardware keyboard ( on the devices that have it) you can capture it using KeyCode.

Here you can find an extensive list of all the keys you can intercept.

To do it:

@Override 
public boolean onKeyDown(int keyCode, KeyEvent event) {

switch (keyCode) {
    case KeyEvent.KEYCODE_STAR: //here you check any key you want
    {
        //your code here
        return true;
    }
}
return super.onKeyDown(keyCode, event);
}

EDIT

Answering your comment, I don't believe this is possible. The KeyDown/Up events are handled on Activities. And you won't have an Activity active. Check this out!

EDIT

Yeah, according to this guy you can't.

Community
  • 1
  • 1
caiocpricci2
  • 7,714
  • 10
  • 56
  • 88
  • thanks.But I want that it should be worked untill our application is not uninstalled i.e. if another application is open then the event specifies on a specific button in previous application should be worked. – amardeep Mar 23 '13 at 15:34
0

If the button is within your own app, then yes.

If you mean a button in any other app (I think you mean the * key on the dial pad), then no.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195