// 申请su权限
Process process = Runtime.getRuntime().exec("su");
dataOutputStream = new DataOutputStream(process.getOutputStream());
// 执行pm install命令
String command = "pm install -r " + apkPath + "\n";
dataOutputStream.write(command.getBytes(Charset.forName("utf-8")));
dataOutputStream.flush();
dataOutputStream.writeBytes("exit\n");
dataOutputStream.flush();
process.waitFor();
errorStream = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String msg = "";
String line;
// 读取命令的执行结果
while ((line = errorStream.readLine()) != null) {
msg += line;
}
Log.d("TAG", "install msg is " + msg);
// 如果执行结果中包含Failure字样就认为是安装失败,否则就认为安装成功
if (!msg.contains("Failure")) {
result = true;
}
InstallAppProgress.java PackageInstallerActivity.java +PackageInstallerActivityHide.java PackageUtil.java UninstallAppProgress.java UninstallerActivity.java +UninstallerActivityHide.java
<application android:label="@string/app_name"> <activity android:name=".PackageInstallerActivity" android:theme="@android:style/Theme.Holo.DialogWhenLarge" android:configChanges="orientation|keyboardHidden"> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <data android:scheme="content"/> <data android:scheme="file"/> <data android:mimeType="application/vnd.android.package-archive"/> </intent-filter> </activity> <activity android:name=".PackageInstallerHideActivity" android:theme="@android:style/Theme.NoDisplay" android:configChanges="orientation|keyboardHidden"> <intent-filter> <action android:name="android.intent.action.VIEW.HIDE"/> <category android:name="android.intent.category.DEFAULT"/> <data android:scheme="content"/> <data android:scheme="file"/> <data android:mimeType="application/vnd.android.package-archive"/> </intent-filter> </activity> <activity android:name=".UninstallerActivityHide" android:theme="@android:style/Theme.NoDisplay" android:configChanges="orientation|keyboardHidden" android:excludeFromRecents="true"> <intent-filter> <action android:name="android.intent.action.VIEW"/> <action android:name="android.intent.action.DELETE.HIDE"/> <category android:name="android.intent.category.DEFAULT"/> <data android:scheme="package"/> </intent-filter> </activity>
Intent install_hide_intent = new Intent("android.intent.action.VIEW.HIDE");
install_hide_intent .setDataAndType(Uri.parse("[file:///sdcard/hello.apk](file:///sdcard/hello.apk)"),
"application/vnd.android.package-archive");
startActivityForResult(install_hide_intent, INSTALL_RUSULT);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有