2017-04-25 56 views
1

問這個問題,我試圖與StackOverflow上這個話題的衆多解決方案之前,但一些解決方案是混亂,一些解決方案不工作可能是一個機器人版本問題。禁用後,最近使用的應用按鈕,電源按鈕,家和家長按按鈕

因此,我問這個問題,所以請幫我到當活動啓動時禁用後面,最近的應用程序按鈕,電源按鈕,家庭和家庭長按鈕

答案應該在android 4.4.x以上版本以上。

謝謝。

+0

AFAIK,你不能。用戶應始終有辦法擺脫任何應用程序,或關閉他/她的設備,無論他/她在哪裏。 – Fustigador

+1

@Fustigador我同意你的觀點,但有些應用程序需要像SpinMe鬧鐘那樣的功能,使用此功能強制用戶醒來。 – Ali

+0

也許...但如果有辦法,不會是一件容易的事。 – Fustigador

回答

0

你試過onBackPressed()函數嗎?當活動已經檢測到用戶的返回鍵的按下

@Override 
    public void onBackPressed() 
    { 
     // code here to show dialog 
     super.onBackPressed(); // optional depending on your needs 
    } 

onBackPressed()函數被調用。 developer.android.com 我正在使用這個來禁用活動上的回按按鈕。

對於其他像電源按鈕按下,你可以嘗試下面的代碼。

public boolean onKeyDown(int keyCode, KeyEvent event) { 
    if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) { 
     // do what you want with the power button 
     return true; 
    } 
    return super.onKeyDown(keyCode, event); 
} 

OR

@Override 
public boolean dispatchKeyEvent(KeyEvent event) { 
    if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) { 
     Intent i = new Intent(this, ActivitySetupMenu.class); 
     startActivity(i); 
     return true; 
    } 

    return super.dispatchKeyEvent(event); 
} 

你需要了解Android的KeyEvent的。 KeyEvent.html

如果有幫助,請接受答案。

+0

別人怎麼樣? – Ali

+0

只是後退按鈕代碼工作... – Ali