Android to lock the home button and back button in android

泪湿孤枕 提交于 2021-02-07 10:06:42

问题


hey i want to make an Application which will start when the phone will start, which i am able to do so but my problem is to disable the "Home Button" & "Back Button" on start up an it should only be enable when i click an button on my activity which will be the home screen on start up, please help me out..


回答1:


You have to make an intent-filter for BOOT_COMPLETED. You can get the tutorials from here and here

To disable HOME and BACK

Lets se... If your app is running and visible to user then you can do that by using the following code

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)  {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR
        && (keyCode == KeyEvent.KEYCODE_BACK    || keyCode == KeyEvent.KEYCODE_HOME)
    && event.getRepeatCount() == 0) 
    {
        onBackPressed();
    }
    return super.onKeyDown(keyCode, event);
}

@Override
public void onBackPressed() {
    // Do nothing
    return;
}

But if your app is not running then it is not possible for you to do that how ever you can make your custom launcher in that wey you can decide weather to show the screen or not

OR

You can disable the home key check here



来源:https://stackoverflow.com/questions/13282544/android-to-lock-the-home-button-and-back-button-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!