Android Read system files Wpa_supplicant

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.