Android examples for App:Package
uninstall Package
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import android.util.Log; public class Main { public static boolean uninsPackage(int type, String packageName) { Log.i("yangtong", "uninsPackage >>" + packageName); switch (type) { case 0:/*from ww w . ja va 2s.com*/ return uninsSilent(packageName); case 1: return uninsSilent(packageName); default: return uninsSilent(packageName); } } private static boolean uninsSilent(String packageName) { String[] args = { "pm", "uninstall", packageName }; String result = ""; ProcessBuilder processBuilder = new ProcessBuilder(args); Process process = null; InputStream errIs = null; InputStream inIs = null; ByteArrayOutputStream baos = null; try { baos = new ByteArrayOutputStream(); int read = -1; process = processBuilder.start(); errIs = process.getErrorStream(); while ((read = errIs.read()) != -1) { baos.write(read); } inIs = process.getInputStream(); read = -1; while ((read = inIs.read()) != -1) { baos.write(read); } byte[] data = baos.toByteArray(); result = new String(data); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } finally { try { if (inIs != null) inIs.close(); if (errIs != null) errIs.close(); if (baos != null) baos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (process != null) process.destroy(); } Log.i("yangtong", "unins result >>" + result); return result.contains("uccess") ? true : false; } }