how to disable home button in android?

前端 未结 4 1864
太阳男子
太阳男子 2020-11-28 13:14

i want to disable android device home button when my app runs.

i have tried following code but it din\'t help :

@Override
    public bo         


        
相关标签:
4条回答
  • 2020-11-28 13:33

    You can use below method to disable the Home key in android:

    @Override
    public void onAttachedToWindow() {
        this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
        super.onAttachedToWindow();
    }
    
    0 讨论(0)
  • 2020-11-28 13:42

    You cannot disable home button.

    There is no way to intercept the home button on Android, unless you make your app the home screen. This is for security reasons, so that malicious apps cannot take over your device by overriding all the buttons that can exit.

    Home button is one sure short way to navigate to home screen.

    If you want to handle the HOME button, implement a home screen.

    Not able disable Home button on specific android devices

    Check the answer by commonsware

    0 讨论(0)
  • 2020-11-28 13:44

    You can use Android-HomeKey-Locker to disable HOME KEY and other system keys(such as BACK KEY and MENU KEY)

    NOTE

    It seems that the solution only works on devices with hard home key

    Hope this will help you in your application. Thanks.

    0 讨论(0)
  • 2020-11-28 13:46

    I think this can be done in another style if suits your requirement. By creating your activity as home activity. If you want to disable home button and show your custom application activity as launcher when home button is pressed. Just add these lines in manifest for that activity for which you want your launcher.

    <activity
                android:name="com.example.TempActivity"
                android:clearTaskOnLaunch="true"
                android:excludeFromRecents="true"
                android:launchMode="singleTask"
                android:screenOrientation="landscape"
                android:stateNotNeeded="true" >
                 <intent-filter >
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.HOME" />
                    <category android:name="android.intent.category.DEFAULT" />
    
                </intent-filter>
    </activity>
    

    After adding and run your application. if user presses the home button, Android will ask for which launcher you want your home. Then your have to select your application launcher ALWAYS not ONLY ONCE.

    if you want fully disable the user, so that he cant move to another screen then set theme to fullscreen with NoTitlebar.

    0 讨论(0)
提交回复
热议问题