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..

abdul
  • 1,531
  • 1
  • 14
  • 29
Mano
  • 67
  • 1
  • 13

4 Answers4

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;
B M
  • 1,863
  • 1
  • 25
  • 40
  • 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 – Mano Sep 10 '14 at 07:32
  • this is original solution for CPU Core http://stackoverflow.com/questions/7962155/how-can-you-detect-a-dual-core-cpu-on-an-android-device-from-code – B M Sep 10 '14 at 07:48
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

abdul
  • 1,531
  • 1
  • 14
  • 29
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");
ivan.sim
  • 8,972
  • 8
  • 47
  • 63
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.

Lodewyk
  • 396
  • 4
  • 6