public boolean silentInstall1()
{
String[] args =
{"pm", "install", "-i", "此处为包名", "-r",
UPDATE_APK_PATH};
if (Build.VERSION.SDK_INT >= 24)
{
args = new String[]
{"pm", "install", "-r", "-i", "此处为包名", "--user",
"0", UPDATE_APK_PATH};
}
String result = "EMPTY";
ProcessBuilder processBuilder = new ProcessBuilder(args);
Process process = null;
InputStream inIs = null;
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int read = -1;
process = processBuilder.start();
baos.write('/');
inIs = process.getInputStream();
while ((read = inIs.read()) != -1)
{
baos.write(read);
}
byte[] data = baos.toByteArray();
result = new String(data, "utf-8");
Log.d("result111", "resultString-------->>>" + result);
baos.close();
} catch (IOException e)
{
Log.d("result1111", "静默安装无效!!!");
} finally
{
try
{
if (inIs != null)
{
inIs.close();
}
} catch (IOException e)
{
}
if (process != null)
{
process.destroy();
}
}
return result.contains("Success");
}
android 静默安装apk(区别7.0)
最新推荐文章于 2022-11-09 14:56:46 发布