your programing

Android에서 홈 및 기타 시스템 버튼을 비활성화하는 방법은 무엇입니까?

lovepro 2020. 10. 14. 08:15
반응형

Android에서 홈 및 기타 시스템 버튼을 비활성화하는 방법은 무엇입니까?


Android 애플리케이션에서 홈 및 기타 시스템 버튼을 비활성화해야합니다.

예 : MX Player ( Google Play 참조 )-플레이어 화면에서 "잠금"아이콘을 누르면 모든 하드웨어 및 소프트웨어 시스템 버튼이 잠 깁니다.

루팅없이 잘 작동합니다.

Android 버전이 다른 일부 장치에서 테스트했습니다. Kids Lock (플러그인)을 분해하려고했지만 작동 방식에 대한 단서가 없습니다.

다음을 위해 Kids Lock (플러그인)과 같은 솔루션이 필요합니다 MX Player.-홈, 뒤로 및 기타 모든 시스템 버튼을 비활성화합니다.

어떤 제안?


먼저 Home버튼이나 다른 버튼 (예 : Back버튼) 을 비활성화하고 싶다면 오랫동안 열심히 생각하십시오 . 이것은해야 할 일이 아닙니다 (적어도 대부분의 경우 이것은 나쁜 디자인입니다. ). 나는 나만을 위해 말할 수 있지만 OS 버튼을 클릭하는 것과 같은 작업을 수행 할 수없는 앱을 다운로드 한 경우 다음으로 해당 앱을 제거하고 매우 나쁜 리뷰를 남깁니다. 또한 귀하의 앱이 App Store에 표시되지 않을 것이라고 생각합니다.

지금...

주의 사항 MX Player: 다른 응용 프로그램의 위에 그릴 수있는 권한을 요구하고 MX 플레이어 권한
당신이 무시할 수 없습니다 때문에 Home버튼 Android장치 (최신 OS 버전 적어도 어떤을). MX Player앱을 "잠그고" Home버튼을 클릭하면 런처 위에 표시됩니다.
좀 더 간단하고 이해하기 쉬운 예를 보려면 Facebook Messenger 앱을 참조하십시오 .

MX 플레이어 Status BarNavigation Bar"재정의" 에 대한 추가 정보를 제공하라는 요청을 받았기 때문에 이러한 주제도 포함하도록 답변을 편집하고 있습니다.

먼저 MX Player는 .NET에서 몰입 형 전체 화면 모드 ( DevBytes Video )를 사용하고 KitKat있습니다.
Android 4.4 (API 레벨 19)는 앱이 진정한 "전체 화면"이되도록하는 setSystemUiVisibility ()에 대한 새로운 SYSTEM_UI_FLAG_IMMERSIVE 플래그를 도입합니다 . 이 플래그를 SYSTEM_UI_FLAG_HIDE_NAVIGATIONSYSTEM_UI_FLAG_FULLSCREEN 플래그 결합 하면 탐색 및 상태 표시 줄을 숨기고 앱이 화면의 모든 터치 이벤트를 캡처 할 수 있습니다.

몰입 형 전체 화면 모드가 활성화되면 활동은 모든 터치 이벤트를 계속 수신합니다. 사용자는 시스템 표시 줄이 일반적으로 나타나는 영역을 따라 안쪽으로 스 와이프하여 시스템 표시 줄을 표시 할 수 있습니다. 이렇게하면 SYSTEM_UI_FLAG_HIDE_NAVIGATION 플래그 (및 적용된 경우 SYSTEM_UI_FLAG_FULLSCREEN 플래그) 지워져 시스템 표시 줄이 표시됩니다. 이것은 또한 설정된 경우 View.OnSystemUiVisibilityChangeListener를 트리거합니다 . 그러나 잠시 후 시스템 표시 줄을 자동으로 다시 숨기려면 대신 SYSTEM_UI_FLAG_IMMERSIVE_STICKY 플래그 를 사용할 수 있습니다 . 이 모드에서 일시적으로 표시되는 시스템 표시 줄은 일시적인 상태이므로 플래그의 "고정"버전은 리스너를 트리거하지 않습니다.

둘째 : 상태 바 숨기기
: 제 탐색 표시 줄 숨기기
하시기 바랍니다 메모를 그 몰입 전체 화면을 사용하는 경우에만 있지만 KitKat을 숨기고, Status Bar그리고 Navigation Bar뿐만 아니라입니다 KitKat.

2 일과 3 일에 대해 할 말이 많지 않습니다. 당신은 내가 믿는 아이디어를 얻었습니다. 어쨌든 그것은 빠른 읽기입니다. View.OnSystemUiVisibilityChangeListener에 세심한주의를 기울이 십시오 .

내가 의미하는 바를 설명하는 요점을 추가했지만 완전하지 않고 수정이 필요하지만 아이디어를 얻을 수 있습니다. https://gist.github.com/Epsiloni/8303531

이것을 구현하는 행운을 빕니다.


나는 shaobin0604의 대답을 따랐고 마침내 다음을 추가하여 HOME 버튼을 잠글 수있었습니다.

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

AndroidManifest.xml당신이해야 할 모든 복사하는 것입니다 HomeKeyLocker.java에서 shaobin의 lib 디렉토리 프로젝트와처럼 그것을 구현 shaobin의 예 . BTW : 내 AVD의 Android 버전은 Android 4.0.3 입니다.


Android-HomeKey-Locker 를 사용하여 HOME KEY 및 기타 시스템 키 (예 : BACK KEY 및 MENU KEY)를 비활성화 할 수 있습니다.

이것이 귀하의 신청서에 도움이되기를 바랍니다. 감사.


여기에 언급 된 화면 고정 기능을 사용하여 홈 및 최근 버튼 Android 5.0을 비활성화 할 수 있습니다 .

Android 5.0에는 사용자가 작업을 떠나거나 알림으로 인해 중단되는 것을 일시적으로 제한 할 수있는 새로운 화면 고정 API가 도입되었습니다. 예를 들어 Android 또는 단일 목적 또는 키오스크 애플리케이션에서 높은 위험 평가 요구 사항을 지원하기 위해 교육 앱을 개발하는 경우 사용할 수 있습니다. 앱에서 화면 고정을 활성화하면 앱이 모드를 종료 할 때까지 사용자가 알림을 보거나 다른 앱에 액세스하거나 홈 화면으로 돌아갈 수 없습니다.

기기를 키오스크로 잠글 수 있습니다. 탐색 모음은 숨겨지지 않지만 홈 및 최근 버튼은 모드 활성화 방법에 따라 제거하거나 비활성화 할 수 있습니다. 여기 에서이 기능을 테스트 한 후 몇 가지 정보를 썼습니다 .


추측 일 뿐이지 만 SYSTEM_ALERT_WINDOW 권한 ( "다른 앱 위에 그리기"로 표시됨, 여기 참조 )을 사용하면 가능할 수 있습니다. 앱을 전체 화면, 시스템 경고 유형 창으로 표시합니다. 이렇게하면 홈 화면을 포함한 다른 모든 앱이 숨겨 지므로 홈을 눌러도 눈에 보이는 효과없이 실제로 비활성화 되지 않습니다 .

MX Player에는이 권한이 선언되어 있으며 Facebook Messenger에는 " 채팅 헤드 " 를 표시하는데도 권한이 있으므로 해결책이 될 수 있습니다.

업데이트 (내 의견에서 추가됨) : 다음으로 터치 이벤트 캡처 / OnSystemUiVisibilityChangeListener 사용과 함께 SYSTEM_UI_FLAG_HIDE_NAVIGATION을 사용하여 기본 동작 (터치시 나타나는 탐색 모음)을 재정의합니다. 또한 몰입 형 종료 제스처가 작동하지 않는다고 말 했으므로 SYSTEM_UI_FLAG_IMMERSIVE_STICKY도 설정해 볼 수 있습니다 (SYSTEM_UI_FLAG_FULLSCREEN 및 SYSTEM_UI_FLAG_HIDE_NAVIGATION 사용).


이전에는 홈 버튼을 비활성화 할 수 있었지만 지금은 그렇지 않습니다. 사용자를 가두는 악성 소프트웨어 때문입니다.

자세한 내용은 여기에서 확인할 수 있습니다. Android 4.0 이상에서 홈 버튼 비활성화

마지막으로이 다른 질문에서 볼 수 있듯이 뒤로 버튼을 비활성화 할 수 있습니다. 안드로이드에서 뒤로 버튼 비활성화


먼저 메서드를 만듭니다.

public void hideNavigationBar() {
        final View decorView = this.getWindow().getDecorView();
        final int uiOptions =
                View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;

        Timer timer = new Timer();
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                YourActivityName.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        decorView.setSystemUiVisibility(uiOptions);

                    }
                });
            }
        };

        timer.scheduleAtFixedRate(task, 1, 2);

    }

그런 다음 onCreate()활동 방법에 따라 호출합니다 . onResume()메서드에서 다시 호출하십시오 . 그런 다음 다음과 같이 활동에 다른 방법을 추가 할 수 있습니다.

@Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        hideNavigationBar();
    }

그것이 될 것입니다. 다음 번에 사용자가 화면을 터치 할 때까지 화면을 잠그고 Timer 클래스에서 지연을 변경할 수 있으며 해당 인스턴스에 대한 변경을 허용 한 다음 다시 화면을 잠급니다.


나도 언젠가 이것을 찾고 있었고 마침내 필요에 따라 할 수있었습니다. @Assaf Gamliel 덕분에 그의 대답은 나를 올바른 길로 인도했습니다. 나는 약간의 수정과 함께이 튜토리얼을 따랐다 . Type을 지정하는 동안 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR대신 지정 했습니다 WindowManager.LayoutParams.TYPE_PHONE. 그렇지 않으면 "오버레이"가 시스템 표시 줄을 숨기지 않습니다. 플래그, 높이, 너비 등을 가지고 놀 수 있으므로 원하는대로 작동 할 수 있습니다.


Android 5.0 이상을 타겟팅하는 경우. 다음을 사용할 수 있습니다.

Activity.startLockTask()

홈 버튼을 비활성화하는 방법을 모르겠습니다. 내 지식이있는 한 나는 다음 링크를 얻었다.

링크를 참조하십시오 : -http : //developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_HOME

키 코드 상수 : 홈 키. 이 키는 프레임 워크에서 처리되며 응용 프로그램에 전달되지 않습니다.

하지만 뒤로 버튼을 비활성화 할 수 있습니다. 다음 코드가 도움이되기를 바랍니다.

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

ICS onwords에서 홈 버튼을 비활성화 할 수 없지만 다음과 같이 다른 버튼을 비활성화 할 수 있습니다.

@Override
public boolean dispatchKeyEvent(KeyEvent keyEvent){
   return true;
}

Post ICS, 즉 Android 4+, 즉 보안상의 이유로 HomeButton의 재정의가 제거되어 애플리케이션이 멀웨어로 판명 될 경우 사용자 종료를 활성화합니다.

Plus, it is not a really good practice to not let the user navigate away from the application. But, since you are making a lock screen application, what you can do is declare the activity as a Launcher , so that when the HomeButton is pressed it will simply restart your application and remain there itself (the users would notice nothing but a slight flicker in the screen).

You can go through the following link:

http://dharmendra4android.blogspot.in/2012/05/override-home-button-in-android.html


Frankly it is not possible to disable the home button at least on new api levels , that is from 4.0 onwards. It is also not advisable to do that. You can however, block the back button by overriding the

public void onBackPressed() {
    // do not call super onBackPressed.
}

in order to override the home button, you could use a timer for example, and after every time check if the main screen is your screen or not, or your package is on top or not, (i am sure you will get links to it), and display your activity using the flag single_top.

That way , even if the home button is pressed you will be able to bring your app to the top.

Also make sure that the app has a way to exit, because such kind of apps can really be annoying and should never be developed.

Happy coding.

P.S: It is not possible to intercept the home event, when the home button is pressed.

You can use on attach to window methods and also keyguard methods, but not for api levels from 4.0 onwards.


Using rotation causes an exception, So I've fixed my activity using this:

HomeKeyLocker locker;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_splash);

    locker = new HomeKeyLocker();               
    locker.lock(this);
}

@Override
protected void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    locker.unlock();
}

@Override
public void onConfigurationChanged(Configuration config) {
    super.onConfigurationChanged(config);
    locker.lock(this);
}

You will need to use the @Lê Quang Duy suggestion.


Refreshing an old topic. I was able to achieve that my activity does not fold when the home button (physical or virtual) is pressed. Here is my code for activity onCreate() method:

super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alarm_screen);
        context = getApplicationContext();
        int windowType;
        if (Build.VERSION.SDK_INT>=26) windowType = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
        else windowType = WindowManager.LayoutParams.TYPE_TOAST;
        final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                windowType,
                WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                        | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                        | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                        | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                        | WindowManager.LayoutParams.FLAG_FULLSCREEN,
                PixelFormat.TRANSLUCENT
        );
        wm = (WindowManager) getApplicationContext()
                .getSystemService(Context.WINDOW_SERVICE);

        mTopView = (ViewGroup) getLayoutInflater().inflate(R.layout.activity_alarm_screen, null);
        getWindow().setAttributes(params);
        //Set up your views here
        testView = mTopView.findViewById(R.id.test);
        wm.addView(mTopView, params);

On API 26 and abovem you need to get screen overlay permission from the user. Tested on Android 7 and 8.


I'm working on an application that needs to lock the tablet just for application. First I put my app as MainLauncher, then I lock the taskbar using an AndroidView. Finally I block the tablet. It is not a feature that I indicate to use across multiple tablet models, since each device model has a feature to block it.

But overall it works for everyone. You can use the commands

Java.Lang.Runtime.GetRuntime().Exec("su -c sed -i '/VOLUME_UP/s/^# //g' /system/usr/keylayout/Generic.kl");

as an example to disable the buttons. But everything is based on changing the system files, inside the folder "/ system / usr / keylayout / ...". NOTE: Only works on rooted devices.

Another way I'm trying though still developing is using StreamWrite and StreamReader to access the RootDirectory and rewrite the whole file to disable and enable the buttons.

Hope this helps.

And any questions remain available.


For anyone looking to completely remove the soft-nav on a rooted (or custom ROM) android device, you can modify the build.prop text file within the system folder.

Set the following variable/value:

gemu.hw.mainkeys=1

This is what vendors use to disable the soft nav, when they have physical buttons.


2 ~ 3 년 후에 답변 해 주셔서 죄송합니다. 그러나 모든 시스템 버튼의 활동을 숨길 수 있습니다. 내 답변을 확인하십시오 모든 활동에서 가상 홈 버튼을 비활성화하는 방법은 무엇입니까? .

참고 URL : https://stackoverflow.com/questions/17549478/how-to-disable-home-and-other-system-buttons-in-android

반응형