How we can disable navigation soft buttons home,recent

百般思念 提交于 2020-01-03 03:04:31

问题


Im working on lockscreen in android How we can disable navigation soft buttons, have tried all the ways, systemoverlay but its doesnt work, on pressing home button its kill the service and activity.


回答1:


  1. back button can be controlled by overriding the onbackpressed() method.

  2. Homebutton can controlled by making your application a launch.

 <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>

above code shows intentfilter for creating an launcher. For more info google about making an app a launcher app.

  1. the recent app button can be controlled by bringing your app by using moveTaskToFront in your onpause function of the activity(This works only in and after honeycomb).

add the below code in your

ActivityManager activityManager = (ActivityManager) getApplicationContext() .getSystemService(Context.ACTIVITY_SERVICE);

activityManager.moveTaskToFront(getTaskId(), ActivityManager.MOVE_TASK_NO_USER_ACTION);




回答2:


You cannot override the home button on version 4.0+ This is made for security purpose.

However, you can create a service that shows a window that handles all touch events. Take a look at the best answer at this question

You may also look at some 'App Lock' applications, cause they use the same technique.

But this way doesn't work completely. On some devices, it is possible to open NotificationBar above your service.


There is also another way, and it can override the home button, but does not work for Recent.

You should create an application that will be considered on device as a Launcher Application, but will look like a Locker. Now, when the user unlocks the device, your application starts the actual Launcher Application.



来源:https://stackoverflow.com/questions/34224398/how-we-can-disable-navigation-soft-buttons-home-recent

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