1, requires permission
Android : Name= />
2. Download the Roottools.jar package.
3, two key methods. The main is to get the shell and execute the command line.
Here's how:
private Static BooleanWaitforcommand(Command cmd) { while(!cmd.isfinished ()) {synchronized(CMD) {Try{off(!cmd.isfinished ()) {cmd.wait ( -); } }Catch(Interruptedexception e) {E.printstacktrace (); } }if(!cmd.isexecuting () &&!cmd.isfinished ()) {//Logger.errorst ("Error:command is not executing and was not finished!"); return false; } }//logger.debug ("Command finished!"); return true; }Public StaticArraylist<string>runAndWait1(String cmd, Final BooleanRoot) {Finalarraylist<string> output =NewArraylist<string> (); Command cc =NewCommand (1, CMD) {@Override Public voidCommandoutput(intI, String s) {Output. Add (s);//System.out.println ("Output" +root+s); }@Override Public voidcommandterminated(intI, String s) {System. out. println ("Error"+Root+ s); }@Override Public voidcommandcompleted(intI, inti2) {}};Try{Roottools.Getshell(Root). Add (CC); }Catch(Exception e) {//Logger.errorst ("Exception when trying to run shell command", e); E.printstacktrace ();return null; }if(!Waitforcommand(cc)) {return null; }returnOutput; }
4, the next is a simple call.
FinalFile f=NewFile ("/data/misc/wifi/wpa_supplicant.conf");NewThread () {@Override Public voidRun() {Super. Run (); Arraylist<string> list=NewArraylist<string> (); //String CPath = getcommandlinestring (F.getpath ()); String s="Cat"+F. GetPath (); List =runAndWait1(s, True); for(inti =0; I < List.size (); i++) {Log.e("Content",List.get (i)); }}}.start ();
The output results are as follows:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Read system files Wpa_supplicant