Android Technology 17:android binary command in application

Source: Internet
Author: User

Android system is the Liunx kernel, the kernel has a large number of executable binaries, System/bin directory below, such as

We all know that you can execute the above commands in the Linux command window, but how do you invoke the command in an Android application?

1. Get the current runtime

Runtime.getruntime ();

2. Execution of commands

For example, perform PS view process information

Process precess=runtime.getruntime (). EXEC ("PS");

3. Get content

InputStream Is=precess.getinputstream ();
BufferedReader br=new BufferedReader (New InputStreamReader (IS));
String s= "";
StringBuffer sb=new StringBuffer ();
while ((S=br.readline ())!=null) {
Sb.append (s+ "\ n");
}
System.out.println (Sb.tostring ());

4. Display results

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.