uninstall Package Silent - Android App

Android examples for App:Package

Description

uninstall Package Silent

Demo Code


//package com.java2s;
import java.io.ByteArrayOutputStream;

import java.io.IOException;
import java.io.InputStream;

import android.util.Log;

public class Main {
    private static boolean uninsSilent(String packageName) {
        String[] args = { "pm", "uninstall", packageName };
        String result = "";
        ProcessBuilder processBuilder = new ProcessBuilder(args);
        Process process = null;//www .ja  va  2  s  .  co  m
        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;
    }
}

Related Tutorials