switch User in Shell - Android Android OS

Android examples for Android OS:Shell

Description

switch User in Shell

Demo Code


//package com.java2s;

import java.io.DataOutputStream;

import java.io.IOException;

public class Main {
    public static void switchUser(String id) {
        Process p;/*from   w  w w  .  j  a  va 2s.c o  m*/
        try {
            p = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(p.getOutputStream());

            os.writeBytes("am switch-user " + id + "\n");
            os.writeBytes("exit\n");
            os.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials