We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
里面静默安装apk这方法失效了
The text was updated successfully, but these errors were encountered:
这是我封装的,你可以看看
import com.blankj.utilcode.util.ActivityUtils; import com.blankj.utilcode.util.AppUtils; import com.blankj.utilcode.util.LogUtils; import java.io.PrintWriter;
public class ApkInstaller {
private static final String TAG = "ApkInstaller"; /** * 安装apk,优先静默安装 */ public static void install(String apkPath) { if (AppUtils.isAppRoot()) { //已root设备执行静默安装 boolean silentSuccess = ApkInstaller.clientInstall(apkPath, AppUtils.getAppPackageName(), ActivityUtils.getLauncherActivity()); if (!silentSuccess) { LogUtils.eTag(TAG, "静默安装失败"); //静默安装未成功执行普通安装 AppUtils.installApp(apkPath); } else { LogUtils.eTag(TAG, "静默安装成功"); AppUtils.relaunchApp(true); } } else { //非root设备,普通弹窗安装 AppUtils.installApp(apkPath); } } /** * 静默安装 */ public static boolean clientInstall(String apkPath, String pkgName, String lunActName) { PrintWriter printWriter = null; Process process = null; try { process = Runtime.getRuntime().exec("su"); printWriter = new PrintWriter(process.getOutputStream()); printWriter.println("chmod 777 " + apkPath); printWriter.println("export LD_LIBRARY_PATH=/vendor/lib:/system/lib"); printWriter.println("pm install -r " + apkPath); printWriter.println("am start -n " + pkgName + "/" + lunActName); printWriter.flush(); printWriter.println("exit"); printWriter.flush(); int value = process.waitFor(); return value == 0; } catch (Exception e) { e.printStackTrace(); LogUtils.eTag(TAG, "静默安装apk发生异常," + e.toString()); } finally { if (process != null) { process.destroy(); } if (printWriter != null) { printWriter.close(); } } return false; }
}
Sorry, something went wrong.
Blankj
No branches or pull requests
里面静默安装apk这方法失效了
The text was updated successfully, but these errors were encountered: