安卓(Android) 怎么实现无提示安装包

2019年10月19日12:05:34安卓(Android) 怎么实现无提示安装包已关闭评论 276 996字阅读3分19秒

1.简介

安卓(Android) 怎么实现无提示安装包?——请看下文。

2.示例代码

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


import java.io.ByteArrayOutputStream;

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

public class Main {

    private static boolean installSilent(String packageUrl) {
        String[] args = { "pm", "install", "-r", packageUrl };
        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();
        } 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();
        }
        return result.contains("uccess") ? true : false;
    }
}

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