2

Is there a function or command to get the basic device configurations of android device? Like the RAM size,OS version,number of processor cores, etc..

4 Answers 4

4

All of the device information you can get below the ways. Hope for help.

Get CPU Core of device

/**
 * Gets the number of cores available in this device, across all processors.
 * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
 * @return The number of cores, or 1 if failed to get result
 */
private int getNumCores() {
    //Private Class to display only CPU devices in the directory listing
    class CpuFilter implements FileFilter {
        @Override
        public boolean accept(File pathname) {
            //Check if filename is "cpu", followed by a single digit number
            if(Pattern.matches("cpu[0-9]+", pathname.getName())) {
                return true;
            }
            return false;
        }      
    }

    try {
        //Get directory containing CPU info
        File dir = new File("/sys/devices/system/cpu/");
        //Filter to only list the devices we care about
        File[] files = dir.listFiles(new CpuFilter());
        //Return the number of cores (virtual CPU devices)
        return files.length;
    } catch(Exception e) {
        //Default to return 1 core
        return 1;
    }
}

Get Total RAM of device

public static String getTotalRAM() {
    RandomAccessFile reader = null;
    String load = null;
    try {
        reader = new RandomAccessFile("/proc/meminfo", "r");
        load = reader.readLine();
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        // Streams.close(reader);
    }
    return load;
}

Other information of device

String _OSVERSION = System.getProperty("os.version");
String _RELEASE = android.os.Build.VERSION.RELEASE;
String _DEVICE = android.os.Build.DEVICE; 
String _MODEL = android.os.Build.MODEL; 
String _PRODUCT = android.os.Build.PRODUCT; 
String _BRAND = android.os.Build.BRAND; 
String _DISPLAY = android.os.Build.DISPLAY; 
String _CPU_ABI = android.os.Build.CPU_ABI; 
String _CPU_ABI2 = android.os.Build.CPU_ABI2; 
String _UNKNOWN = android.os.Build.UNKNOWN; 
String _HARDWARE = android.os.Build.HARDWARE;
String _ID = android.os.Build.ID; 
String _MANUFACTURER = android.os.Build.MANUFACTURER; 
String _SERIAL = android.os.Build.SERIAL; 
String _USER = android.os.Build.USER; 
String _HOST = android.os.Build.HOST;
Sign up to request clarification or add additional context in comments.

2 Comments

the getTotalRAM is working perfectly..but the CPU function doesnt provide any result..when i print it gives blank output both in emulator and device
this is original solution for CPU Core stackoverflow.com/questions/7962155/…
2

You can obtain most of the information you want from the /proc/cpuinfo file. Here is a tutorial on how to load and parse that file: How to get Cpu Information on android

Information about the RAM can be obtained from the /proc/meminfo file

Comments

1

Check out the android.os.Build class.

android.os.Build.HARDWARE
android.os.Build.DEVICE             
android.os.Build.MODEL               
android.os.Build.PRODUCT            
android.os.Build.BOARD        
android.os.Build.DISPLAY

etc...

To get the OS version number, you can try

System.getProperty("os.version");

Comments

1

You could look at android.os.Build to determine the phone make and model. From there have a lookup to look up the phone specs based on make and model.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.