Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • If you are looking to override your device home button to work as you desired

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 147
    Comment on it

    If you are looking to know, How to override home button programmatically in android, then below I have provided the simple solution.
    You have to do just a simple thing i.e to override the onKeyDown function in your application, given is the code snippet that opens a dialog box on clicking home button:-

    @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if ((keyCode == KeyEvent.KEYCODE_HOME)) {
                showCustomDialog("This is just an example to open a dialog when you press home button, you can do other thing also");
                return true;
            }
            return false;
        }
    
    void showCustomDialog(String msg)
    {
       AlertDialog.Builder alertDialog;
       alertDialog= new AlertDialog.Builder(activity.this);
       alertDialog.setTitle("");
       alertDialog.setMessage(msg);
       alertDialog.setPositiveButton("OK",new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog,int which) 
                       {
                        dialog.cancel();
              }
            });
       alertDialog.show();
      }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: