Home > Android > Some snippets with android developer

Some snippets with android developer


1. Check SDCard on Android machine:

import android.os.Environment;

private boolean isHaveSDCard(){
return Environment.getExternalStorageDirectory().equals(Environment.MEDIA_MOUNTED);
}
2. Get information about Memory and CPU:
import java.lang;

private String getMemoryInfo(){

ProcessBuilder cmd;
String result = new String();
try{
String[] args  ={“/system/bin/cat”,”/proc/meminfo”};
cmd = new ProcessBuilder(args);
Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[1024];
while(in.read(re) != -1){
result = result + new String(re);
}
in.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
privateString getCPUinfo(){
        ProcessBuilder cmd;
        String result="";
        try{
            String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
            cmd = newProcessBuilder(args);
            java.lang.Process process = cmd.start();
            InputStream in = process.getInputStream();
            byte[] re = newbyte[1024];
            while(in.read(re) != -1){
                result = result + newString(re);
            }
            in.close();
        } catch(Exception ex){
            ex.printStackTrace();
        }
        returnresult;
    }
Source: vietandroid.com
Categories: Android
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: