I am developing an application for android tv box with an IR remote . In my application I have successfully launched a web browser from my code , and I want to close this browser when the user press a button on the IR remote. I have tried to catch the key event by listening for the dispatch key event in my code , but key event is not getting caught . Could Someone please help me out in catching key press event in my application . Thank you
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if(event.getKeyCode()==170) {
// some code
}
return true;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent i = new Intent("android.intent.action.MAIN");
i.setComponent(new ComponentName("org.mozilla.firefox", "org.mozilla.firefox.App"));
Bundle b = new Bundle();
b.putBoolean("new_window", true);
i.putExtras(b);
i.addCategory("android.intent.category.CATEGORY_LAUNCHER");
startActivity(i);
}