Android靜默安裝應用和靜默解除安裝應用
這裡提供兩個Android系統下靜默安裝應用和靜默解除安裝應用的方法,在 5.1 版本系統上執行通過。當然,執行程式碼的應用需要有系統許可權,這就需要應用通過系統簽名檔案進行簽名了,需要使用到 platform.pk8 和 platform.x509.pem 兩個檔案,可以參照我的另一篇文章:Android 用 platform.pk8 和 platform.x509.pem 生成 keystore 系統簽名檔案
/**
* 靜默安裝App
*
* @param apkPath apk路徑
* @return 是否安裝成功
*/
public static boolean installApp(String apkPath) {
Process process = null;
BufferedReader successResult = null;
BufferedReader errorResult = null;
StringBuilder successMsg = new StringBuilder();
StringBuilder errorMsg = new StringBuilder();
try {
process = new ProcessBuilder("pm", "install", "-r", apkPath).start();
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s;
while ((s = successResult.readLine()) != null) {
successMsg.append(s);
}
while ((s = errorResult.readLine()) != null) {
errorMsg.append(s);
}
} catch (Exception e) {
} finally {
try {
if (successResult != null) {
successResult.close();
}
if (errorResult != null) {
errorResult.close();
}
} catch (Exception e) {
}
if (process != null) {
process.destroy();
}
}
//如果含有“success”單詞則認為安裝成功
return successMsg.toString().equalsIgnoreCase("success");
}
/**
* 靜默解除安裝App
*
* @param packageName 包名
* @return 是否解除安裝成功
*/
public static boolean uninstallApp(String packageName) {
Process process = null;
BufferedReader successResult = null;
BufferedReader errorResult = null;
StringBuilder successMsg = new StringBuilder();
StringBuilder errorMsg = new StringBuilder();
try {
process = new ProcessBuilder("pm", "uninstall", packageName).start();
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s;
while ((s = successResult.readLine()) != null) {
successMsg.append(s);
}
while ((s = errorResult.readLine()) != null) {
errorMsg.append(s);
}
} catch (Exception e) {
} finally {
try {
if (successResult != null) {
successResult.close();
}
if (errorResult != null) {
errorResult.close();
}
} catch (Exception e) {
}
if (process != null) {
process.destroy();
}
}
//如果含有“success”單詞則認為解除安裝成功
return successMsg.toString().equalsIgnoreCase("success");
}
/**
* 判斷應用是否存在
*
* @param context 上下文
* @param packageName 包名
* @return 是否存在
*/
private boolean appExist(Context context, String packageName) {
try {
List<PackageInfo> packageInfoList = context.getPackageManager().getInstalledPackages(0);
for (PackageInfo packageInfo : packageInfoList) {
if (packageInfo.packageName.equalsIgnoreCase(packageName)) {
return true;
}
}
} catch (Exception e) {
}
return false;
}
相關文章
- 應用黑名單以及靜默安裝的實現
- rac靜默安裝
- Oracle靜默安裝Oracle
- 【11g 單庫解除安裝、靜默安裝】實驗
- Linux下靜默安裝OraceLinux
- 【靜默】在RHEL 6.5上靜默安裝Oracle 18cOracle
- 靜默安裝and手動建庫
- oracle 19C 靜默安裝Oracle
- 靜默安裝oracle時報錯Oracle
- AnolisOS 7.9 靜默安裝Oacle 11.2.0.4
- centos 7.4靜默安裝oracle 19.3CentOSOracle
- Windows 7平臺靜默安裝11.2.0.4軟體及靜默建庫Windows
- 靜默方式安裝11gR2
- Oracle Linux 7.1 靜默安裝Weblogic 12.2.1.3OracleLinuxWeb
- win10如何禁止靜默執行_win10禁止靜默安裝方法Win10
- RedHat上靜默安裝Oracle11gRedhatOracle
- CentOS 7.2靜默安裝Oracle11gCentOSOracle
- redhat7.2靜默安裝Oracle11.2.0.4RedhatOracle
- CentOS 7.5靜默安裝Oracle 11gCentOSOracle
- Oracle 19C的下載和安裝部署(圖形安裝和靜默安裝)Oracle
- 靜默方式安裝、升級oracle(一): 安裝oracle軟體Oracle
- Android 流氓軟體靜默安裝是怎麼實現的?Android
- 靜默安裝Oracle11g資料庫Oracle資料庫
- 靜默方式安裝oracle 11g 完整攻略Oracle
- oracle11g客戶端靜默安裝Oracle客戶端
- 靜默安裝Oracle資料庫11gOracle資料庫
- 靜默安裝19C RAC的指令碼指令碼
- 免root解除安裝Android預裝應用Android
- windows10系統禁止靜默安裝的方法Windows
- linux7 靜默安裝 11GR2 RACLinux
- Oracle Linux 7.1 靜默安裝Oracle 18c RACOracleLinux
- RedHat 7 靜默安裝Oracle11g的補充RedhatOracle
- Linux下利用指令碼靜默安裝Oracle11GLinux指令碼Oracle
- 19c(19.3) 單機資料庫靜默安裝資料庫
- 靜默方式安裝、升級oracle(二): 建立資料庫Oracle資料庫
- GoldenGate 12.3 MA架構介紹系列(5) - 靜默安裝Go架構
- 【配置安裝】靜默安裝Oracle資料庫軟體12c&19cOracle資料庫
- 阿里雲伺服器靜默安裝Oracle 11.2.0.4.0 -64bit阿里伺服器Oracle
- 靜默安裝Oracle建庫時報Template General Purpose does not existOracle