美文网首页
android root 权限自动安装并打开app

android root 权限自动安装并打开app

作者: 微笑中的你 | 来源:发表于2022-11-16 16:25 被阅读0次

    测试过了。有效的。。。当然必须是具有root权限的才能哦

    path 是 apk的路径,

    packageName 如 com.a.b

    activityName 如 com.a.b.MainActivity

    Kotlin 代码

        /**
         * 安装并打开app 
         */
        fun installAppAndOpenByCmd(path: String, packageName: String, activityName: String) {
    
            val cmd1: String = "am start -n $packageName/$activityName\n"
            val cmd2: String = "pm install -r $path && "
            val cmd = cmd2 + cmd1
            val runtime =  Runtime.getRuntime()
            try {
                val localProcess = runtime.exec("su")
                val localOutputStream = localProcess.outputStream
                val localDataOutputStream = DataOutputStream(localOutputStream)
                localDataOutputStream.writeBytes(cmd)
                localDataOutputStream.flush()
            } catch (e: IOException) {
                e.printStackTrace()
            }
        }
    

    相关文章

      网友评论

          本文标题:android root 权限自动安装并打开app

          本文链接:https://www.haomeiwen.com/subject/fyqexdtx.html