安卓(Android) 怎么无提示卸载包

2019年10月19日12:05:40安卓(Android) 怎么无提示卸载包已关闭评论 285 1067字阅读3分33秒

1.简介

安卓(Android) 怎么无提示卸载包?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


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;
        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) {
            
            e.printStackTrace();
            return false;
        } finally {
            try {
                if (inIs != null)
                    inIs.close();
                if (errIs != null)
                    errIs.close();
                if (baos != null)
                    baos.close();
            } catch (IOException e) {
                
                e.printStackTrace();
            }
            if (process != null)
                process.destroy();
        }
        Log.i("yangtong", "unins result >>" + result);
        return result.contains("uccess") ? true : false;
    }
}

 
继续阅读
编程十万个怎么办