create User using shell command - Android Android OS

Android examples for Android OS:Shell

Description

create User using shell command

Demo Code


//package com.java2s;

import java.io.DataOutputStream;

import java.io.IOException;

public class Main {
    public static void createUser(String name) {
        Process p;/*from   w  ww  .  jav a2 s.c  om*/
        try {
            p = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(p.getOutputStream());

            os.writeBytes("pm create-user \"" + name + "\"\n");
            os.writeBytes("exit\n");
            os.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials