Android ShellUtils手機管理器

1. Android ShellUtils手機管理器

??Android Shell工具類,可用于檢查系統root權限,并在shell或root用戶下執行shell命令。如:
checkRootPermission() 檢查root權限 。execCommand(String[] commands, boolean isRoot, boolean isNeedResultMsg) shell 環境執行命令,第二個參數表示是否root權限執行 execCommand(String command, boolean isRoot) shell環境執行命令。

1.1. 代碼

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;public class ShellUtils {public static final String COMMAND_SU = "su";public static final String COMMAND_SH = "sh";public static final String COMMAND_EXIT = "exit\n";public static final String COMMAND_LINE_END = "\n";public ShellUtils() {}public static boolean checkRootPermission() {return execCommand("echo root", true, false).result == 0;}public static CommandResult execCommand(String command, boolean isRoot) {return execCommand(new String[]{command}, isRoot, true);}public static CommandResult execCommand(List<String> commands, boolean isRoot) {return execCommand(commands == null ? null : (String[])commands.toArray(new String[0]), isRoot, true);}public static CommandResult execCommand(String[] commands, boolean isRoot) {return execCommand(commands, isRoot, true);}public static CommandResult execCommand(String command, boolean isRoot, boolean isNeedResultMsg) {return execCommand(new String[]{command}, isRoot, isNeedResultMsg);}public static CommandResult execCommand(List<String> commands, boolean isRoot, boolean isNeedResultMsg) {return execCommand(commands == null ? null : (String[])commands.toArray(new String[0]), isRoot, isNeedResultMsg);}public static CommandResult execCommand(String[] commands, boolean isRoot, boolean isNeedResultMsg) {int result = -1;if (commands != null && commands.length != 0) {Process process = null;BufferedReader successResult = null;BufferedReader errorResult = null;StringBuilder successMsg = null;StringBuilder errorMsg = null;DataOutputStream os = null;try {process = Runtime.getRuntime().exec(isRoot ? "su" : "sh");os = new DataOutputStream(process.getOutputStream());String[] var13 = commands;int var12 = commands.length;String s;for(int var11 = 0; var11 < var12; ++var11) {s = var13[var11];if (s != null) {os.write(s.getBytes());os.writeBytes("\n");os.flush();}}os.writeBytes("exit\n");os.flush();result = process.waitFor();if (isNeedResultMsg) {successMsg = new StringBuilder();errorMsg = new StringBuilder();successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));while((s = successResult.readLine()) != null) {successMsg.append(s);}while((s = errorResult.readLine()) != null) {errorMsg.append(s);}}} catch (IOException var24) {var24.printStackTrace();} catch (Exception var25) {var25.printStackTrace();} finally {try {if (os != null) {os.close();}if (successResult != null) {successResult.close();}if (errorResult != null) {errorResult.close();}} catch (IOException var23) {var23.printStackTrace();}if (process != null) {process.destroy();}}return new CommandResult(result, successMsg == null ? null : successMsg.toString(), errorMsg == null ? null : errorMsg.toString());} else {return new CommandResult(result, (String)null, (String)null);}}public static class CommandResult {public int result;public String successMsg;public String errorMsg;public CommandResult(int result) {this.result = result;}public CommandResult(int result, String successMsg, String errorMsg) {this.result = result;this.successMsg = successMsg;this.errorMsg = errorMsg;}}
}

1.2. 使用

(1)關機

public void ShutDown(View view) {ShellUtils.execCommand("reboot -p", true);
}

(2)重啟

public void Reboot(View view) {ShellUtils.execCommand("reboot", true);
}

(3)快速重啟

public void FastReboot(View view) {ShellUtils.execCommand("busybox killall system_server", true);
}

(4)進入刷機模式

public void Recovery(View view) {ShellUtils.execCommand("reboot recovery", true);
}

(5)進入引導模式

public void FastBoot(View view) {ShellUtils.execCommand("reboot bootloader", true);
}

1.3. adb shell input keyevent 控制按鍵輸入的數值

??adb shell的功能很強大,可以使用很多功能,今天我們說下通過控制按鍵輸入:adb shell input keyevent xx ,具體數值xx如下
KEYCODE_CALL 進入撥號盤 5
KEYCODE_ENDCALL 掛機鍵 6
KEYCODE_HOME 按鍵Home 3
KEYCODE_MENU 菜單鍵 82
KEYCODE_BACK 返回鍵 4
KEYCODE_SEARCH 搜索鍵 84
KEYCODE_CAMERA 拍照鍵 27
KEYCODE_FOCUS 拍照對焦鍵 80
KEYCODE_POWER 電源鍵 26
KEYCODE_NOTIFICATION 通知鍵 83
KEYCODE_MUTE 話筒靜音鍵 91
KEYCODE_VOLUME_MUTE 揚聲器靜音鍵 164
KEYCODE_VOLUME_UP 音量增加鍵 24
KEYCODE_VOLUME_DOWN 音量減小鍵 25
??控制鍵
KEYCODE_ENTER 回車鍵 66
KEYCODE_ESCAPE ESC鍵 111
KEYCODE_DPAD_CENTER 導航鍵 確定鍵 23
KEYCODE_DPAD_UP 導航鍵 向上 19
KEYCODE_DPAD_DOWN 導航鍵 向下 20
KEYCODE_DPAD_LEFT 導航鍵 向左 21
KEYCODE_DPAD_RIGHT 導航鍵 向右 22
KEYCODE_MOVE_HOME 光標移動到開始鍵 122
KEYCODE_MOVE_END 光標移動到末尾鍵 123
KEYCODE_PAGE_UP 向上翻頁鍵 92
KEYCODE_PAGE_DOWN 向下翻頁鍵 93
KEYCODE_DEL 退格鍵 67
KEYCODE_FORWARD_DEL 刪除鍵 112
KEYCODE_INSERT 插入鍵 124
KEYCODE_TAB Tab鍵 61
KEYCODE_NUM_LOCK 小鍵盤鎖 143
KEYCODE_CAPS_LOCK 大寫鎖定鍵 115
KEYCODE_BREAK Break/Pause鍵 121
KEYCODE_SCROLL_LOCK 滾動鎖定鍵 116
KEYCODE_ZOOM_IN 放大鍵 168
KEYCODE_ZOOM_OUT 縮小鍵 169
??利用命令“adb shell input keyevent <鍵值>”可以實現自動化。例如“adb shell input keyevent 3”就可以按下Home鍵。]
(1)執行返回:adb shell input keyevent 4
(2)執行滅屏亮屏:adb shell input keyevent 26
(3)執行解鎖屏幕:adb shell input keyevent 82

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/713766.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/713766.shtml
英文地址,請注明出處:http://en.pswp.cn/news/713766.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

HTTPS是什么,詳解它的加密過程

目錄 1.前言 2.兩種加密解密方式 2.1對稱加密 2.2非對稱加密 3.HTTPS的加密過程 3.1針對明文的對稱加密 3.2針對密鑰的非對稱加密 3.3證書的作用 1.前言 我們知道HTTP協議是超文本傳輸協議,它被廣泛的應用在客戶端服務器上,用來傳輸文字,圖片,視頻,js,html等.但是這種傳…

java數據結構與算法刷題-----LeetCode572. 另一棵樹的子樹(經典題,樹字符串化KMP)

java數據結構與算法刷題目錄&#xff08;劍指Offer、LeetCode、ACM&#xff09;-----主目錄-----持續更新(進不去說明我沒寫完)&#xff1a;https://blog.csdn.net/grd_java/article/details/123063846 文章目錄 1. 暴力求解&#xff0c;深度優先2. KMP算法進行串匹配 1. 暴力求…

WinForm、Wpf自動升級 AutoUpdater.NET

Github AutoUpdater.NET 目錄 一、IIS部署 更新站點 二、創建Winform 一、IIS部署 更新站點 IIS默認站點目錄下創建 目錄 Downloads、Updates Updates目錄創建文件 UpdateLog.html、AutoUpdaterStarter.xml UpdateLog.html&#xff1a; <html><body><h1…

從零開始手寫RPC框架(2)——Netty入門

學習前需要掌握基本的java網絡編程&#xff0c;可參考這篇博客 目錄 Netty 簡介Netty 使用 kryo 序列化傳輸對象案例客戶端代碼服務端代碼編碼器 Netty 簡介 是什么&#xff1f; Netty 是一個基于 NIO (Non-blocking I/O&#xff0c;非阻塞I/O)的 client-server(客戶端服務器…

mysql學習--binlog與gtid主從同步

基礎環境 基于centOS7-MySQL8.0.35版本 我們先準備一臺主服務器兩臺從服務器來實現我們主從同步的訴求 Master&#xff1a;192.168.75.142 slave1:192.168.75.143 slave&#xff1a;192.168.75.145 binlog主從同步 主庫配置 #我們需要在主從庫中都需要添加server_id&am…

大龍談智能內容開通視頻號啦

大家好&#xff0c;大龍談只能內容開通視頻號了&#xff0c;歡迎大家掃碼關注&#xff1a;

RISC-V特權架構 - 中斷與異常概述

RISC-V特權架構 - 中斷與異常概述 1 中斷概述2 異常概述3 廣義上的異常3.1 同步異常3.2 異步異常3.3 常見同步異常和異步異常 本文屬于《 RISC-V指令集基礎系列教程》之一&#xff0c;歡迎查看其它文章。 1 中斷概述 中斷&#xff08;Interrupt&#xff09;機制&#xff0c;即…

RocketMQ安裝

mq服務端安裝配置啟動把windows做成服務 mq管理界面安裝配置啟動 mq服務端 安裝 RocketMQ下載地址 配置 ROCKETMQ_HOME D:\google-d\rocketmq-all-5.2.0-bin-release啟動 # bin目錄cmd輸入 start mqnamesrv.cmd把windows做成服務 http://t.csdnimg.cn/qd2RD mq管理界面 …

ubuntu22.04安裝mysql8.0

官網下載mysql&#xff1a;MySQL :: Download MySQL Community Server 將mysql-server_8.0.20-2ubuntu20.04_amd64.deb-bundle.tar上傳到/usr/local/src #解壓壓縮文件 tar -xvf mysql-server_8.0.20-2ubuntu20.04_amd64.deb-bundle.tar解壓依賴包依次輸入命令 sudo dpkg -i m…

編程筆記 Golang基礎 045 math包

編程筆記 Golang基礎 045 math包 一、math包主要功能常量&#xff1a;函數&#xff1a;數值運算&#xff1a;三角函數&#xff1a;對數函數&#xff1a;隨機數相關&#xff1a; 二、示例代碼一三、示例代碼二小結 Go 語言的標準庫 math 提供了一系列基礎數學函數和常量&#xf…

EasyRecovery數據恢復軟件2024最新版包括Windows和Mac

EasyRecovery數據恢復軟件適用于多種環境和使用場景。首先&#xff0c;它適用于各種操作系統&#xff0c;包括Windows和Mac。無論用戶使用的是哪種操作系統&#xff0c;都可以使用該軟件進行數據恢復。 其次&#xff0c;EasyRecovery支持從各種存儲設備和媒介中恢復數據&#…

自定義BeanNameGenerator生成規則

通過點進ComponentScan注解進入源碼可以看到 追隨BeanNameGenerator進入源碼可以看到該類是個借口且只有一個方法 點擊上面黑色箭頭出現兩個實現方法 點擊第一個方法 進入determineBeanNameFromAnnotation方法中 通過上訴自定義一個生成beanName方法 先創建一個CustomeBeanN…

使用結構體和類在Unity中管理IMU數據

使用結構體和類在Unity中管理IMU數據 IMU數據簡介使用結構體管理IMU數據結構體的優點結構體的使用場景 使用類管理IMU數據類的優點類的使用場景 結構體(struct) vs 類(class)為什么考慮使用結構體 結論 在Unity開發中&#xff0c;合理地選擇數據結構對于確保游戲和應用的性能和…

60 個 CSS 選擇器,一網打盡!

CSS 選擇器用于選擇 HTML 元素并將樣式應用于它們。使用這些選擇器&#xff0c;可以定義特定條件下應用哪些樣式。除了普通的選擇器外&#xff0c;還有偽類和偽元素&#xff0c;用于選擇具有特定狀態或特定部分的元素&#xff0c;并將樣式應用于它們。本文將通過圖文并茂的方式…

Windows11家庭版安裝Docker

文章目錄 安裝Docker安裝hyper-v繼續解決報錯完成效果圖進一步測試是否完成安裝 安裝Docker windows如何安裝docker 裝好之后&#xff0c;我打開報錯。 安裝hyper-v 按這個視頻操作&#xff1a;Windows 11 家庭版安裝 Hyper-V bat文件里的代碼是&#xff1a; pushd "…

【Educoder數據挖掘實訓】異常值檢測-3σ法

【Educoder數據挖掘實訓】異常值檢測-3σ法 開挖&#xff01; 這個異常值檢測基于的是兩點&#xff1a; 數據往往遵循正態分布在正態分布中&#xff0c; [ μ ? 3 σ , μ 3 σ ] [\mu - 3\sigma, \mu 3\sigma] [μ?3σ,μ3σ]包含了正態分布中 99.74 % 99.74\% 99.74%的數…

【投稿優惠|快速見刊】2024年圖像,機器學習和人工智能國際會議(ICIMLAI 2024)

【投稿優惠|快速見刊】2024年圖像&#xff0c;機器學習和人工智能國際會議&#xff08;ICIMLAI 2024&#xff09; 重要信息 會議官網&#xff1a;http://www.icimlai.com會議地址&#xff1a;深圳召開日期&#xff1a;2024.03.30截稿日期&#xff1a;2024.03.20 &#xff08;先…

2024全國水科技大會暨高氨氮廢水厭氧氨氧化處理技術論壇(四)

一、會議背景 為積極應對“十四五”期間我國生態環境治理面臨的挑戰&#xff0c;加快生態環境科技創新&#xff0c;構建綠色技術創新體系&#xff0c;全面落實科學技術部、生態環境部等部委編制的《“十四五”生態環境領域科技創新專項規劃》&#xff0c;積極落實省校合作&…

pip下載paddle、sklearn、cv2問題

ModuleNotFoundError: No module named ‘paddle‘ ModuleNotFoundError: No module named sklearn No matching distribution found for cv2 Could not build wheels for opencv-python, which is required to install pyproj

什么是BGP網絡 (邊界網關協議)

BGP&#xff08;邊界網關協議&#xff09;是一種用于在互聯網中交換路由信息的協議。作為網關或路由器之間的協議&#xff0c;BGP主要用于幫助確定數據包在網絡中的路徑。它通過在不同自治系統&#xff08;AS&#xff09;之間交換路徑信息&#xff0c;實現了全球互聯網網絡的連…