2017-01-25 135 views
1

我正在嘗試在紮根的android設備上實現Kiosk應用,並且我需要完全禁用導航欄和狀態欄。刪除Android導航欄和頂欄,

這些命令從亞行外殼

禁用工作:

service call activity 42 s16 com.android.systemui 

啓用:

am startservice -n com.android.systemui/.SystemUIService 

那太好了!現在我需要能夠從我的應用程序中完成它。所以要禁用我已經嘗試過:

Process process = Runtime.getRuntime().exec("su service call activity 42 s16 com.android.systemui"); 

當按下我的活動中的按鈕。但沒有任何反應,也沒有例外。儘管舉杯暢飲,稱該應用已獲得超級用戶權利。

任何想法?

回答

3

運行蘇在cmd你可以使用這個

public static void runCmd(String cmd) { 
    DataOutputStream os; 
    try { 
     Process process = Runtime.getRuntime().exec("su"); 
     os = new DataOutputStream(process.getOutputStream()); 
     os.writeBytes(cmd + "\n"); 
     os.writeBytes("exit\n"); 
     os.flush(); 
     os.close(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 

要禁用系統的用戶界面,你可以運行此命令

runCmd("pm disable com.android.systemui && service call activity 42 s16 com.android.systemui"); 

如果你想啓用回

runCmd("pm enable com.android.systemui && am startservice -n com.android.systemui/.SystemUIService"); 
+0

完美地工作!謝謝! – Jolle

+0

當我運行這個命令時,導航欄會消失,但我不能再觸摸屏幕 – alexislg

+0

@alexislg你解決了這個不可觸摸的屏幕問題嗎?不能使它在API 23+(棉花糖)上工作... –

0

拆分蘇呼和命令調用:

try{ 
    Process su = Runtime.getRuntime().exec("su"); 
    DataOutputStream outputStream = new DataOutputStream(su.getOutputStream()); 

    outputStream.writeBytes("service call activity 42 s16 com.android.systemui"); 
    outputStream.flush(); 

    outputStream.writeBytes("exit\n"); 
    outputStream.flush(); 
    su.waitFor(); 
}catch(IOException e){ 
    throw new Exception(e); 
}catch(InterruptedException e){ 
    throw new Exception(e); 
} 
0

藉助Android 5多,你可以試試這招:

settings put secure user_setup_complete 0 
+0

這不會刪除導航欄只會禁用主頁按鈕。 –

+0

在我的設備上它將刪除所有內容。我的應用程序處於身臨其境的模式 – alexislg

+0

哦,我現在看到它。我認爲它就像「服務電話活動......」一樣工作。 –