首页 > 解决方案 > 在根设备android中安装apk后启动应用程序

问题描述

嗨,我想从 sd 卡安装 apk 到 root android 设备,我安装成功 apk 但安装后没有打开应用程序,它在 android 中显示板菜单,安装后如何启动应用程序

String path = "/sdcard/Android/data/com.apk.applicaiton/files/ApkFile/test.apk";

public static Boolean InstallApk(String path)
{
    File file = new File(path);
    if(file.exists()){
        try {
            Process proc = Runtime.getRuntime().exec(new String[]{"su","-c","pm install -r -d " + path});
            proc.waitFor();
            BufferedReader input = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
            String line;
            Boolean hasError = false;
            while ((line = input.readLine()) != null) {
                if(line.contains("Failure")){
                    hasError = true;
                }
            }
            if(proc.exitValue() != 0 || hasError){
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

        return true;
    }else{
        Timber.i("Path is not found:%s", path);
    }

    return false;
}

标签: androidapkroot

解决方案


推荐阅读