Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Getting RAM Details Android.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 213
    Comment on it

    This Blog is about RAM detail that Total Ram size your Android Device and used Ram size in your Android Device.

    From API level 16 Android gives properties to get Ram information.

     

    In this tutorial I will explain to get RAM size for below API 16 and from API level 16.

    1. Create Project.

    2. Create Activity.

    3.  Write below method to get Total RAM size on below API level 16.

        public double getTotalRAM() {
    
            RandomAccessFile reader = null;
            String load = null;
            double totRam = 0;
            try {
                reader = new RandomAccessFile("/proc/meminfo", "r");
                load = reader.readLine();
    
                // Get the Number value from the string
                Pattern p = Pattern.compile("(\\d+)");
                Matcher m = p.matcher(load);
                String value = "";
                while (m.find()) {
                    value = m.group(1);
                    // System.out.println("Ram : " + value);
                }
                reader.close();
    
                totRam = Double.parseDouble(value);
    
            } catch (IOException ex) {
                ex.printStackTrace();
            }
    
            return totRam;
        }

    4. Call this method from where you want RAM size.

    5. Method will return Double value which define size in bytes.

    6. Now Move on to After API level 16.

    7. Get ActivityManager Instance.

    ActivityManager actManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);

    8. Get MemoryInfo Instance.

     ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();

    9. Get MemoryInfo of activityManager.

      actManager.getMemoryInfo(memInfo);

    10. Get total Memory from MemoryInfo object's property.

     long totalMemory = memInfo.totalMem;

    11. Get Available memory from MemoryInfo's property. 

      long availMem = memInfo.availMem;

    Total memory and availMemory are in long type.

     

    Happy Coding :D

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: