Read android device total ammount of ram with /proc/meminfo

后端 未结 3 1282
暖寄归人
暖寄归人 2021-01-16 09:56

I am looking into reading the android device\'s total ammount of physical RAM.

I understand that these informations are stored in /proc/meminfo.

how can i r

3条回答
  •  无人及你
    2021-01-16 10:17

    try this :

       public void getTotalMemory() {  
        {
        String str1 = "/proc/meminfo";
        String str2;        
        String[] arrayOfString;
        long initial_memory = 0;
        try {
        FileReader localFileReader = new FileReader(str1);
        BufferedReader localBufferedReader = new BufferedReader(    localFileReader, 8192);
        str2 = localBufferedReader.readLine();//meminfo
        arrayOfString = str2.split("\\s+");
        for (String num : arrayOfString) {
        Log.i(str2, num + "\t");
        }
        //total Memory
        initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024;   
        localBufferedReader.close();
        } 
        catch (IOException e) 
        {       
        }
      }  
    

    when you read this file you will get Total Memory in First Line like:

    MemTotal:          94096 kB
    

提交回复
热议问题