Android獲取儲存信息以及內(nèi)存信息可以用adb命令查看。
成都創(chuàng)新互聯(lián)提供成都網(wǎng)站制作、網(wǎng)站設計、網(wǎng)頁設計,品牌網(wǎng)站建設,廣告投放等致力于企業(yè)網(wǎng)站建設與公司網(wǎng)站制作,10多年的網(wǎng)站開發(fā)和建站經(jīng)驗,助力企業(yè)信息化建設,成功案例突破上1000+,是您實現(xiàn)網(wǎng)站建設的好選擇.
adb查看系統(tǒng)內(nèi)存信息以及儲存信息:
命令:adb shell cat /proc/meminfo
代碼:
private static final String FILENAME_PROC_MEMINFO = "/proc/meminfo"; /** * 獲取手機內(nèi)存總大小 * @return */ public static String getTotalMemorySize() { try { FileReader fr = new FileReader(FILENAME_PROC_MEMINFO); BufferedReader br = new BufferedReader(fr, 2048); // String memoryLine = br.readLine(); String subMemoryLine = ""; String Line = ""; while ((Line = br.readLine()) != null) { if (Line.contains("MemTotal:")){ subMemoryLine = Line.substring(Line.indexOf("MemTotal:")); break; } } br.close(); Matcher mer = Pattern.compile("^[0-9]+$").matcher(subMemoryLine.replaceAll("\\D+", "")); //如果為正整數(shù)就說明數(shù)據(jù)正確的,確保在Double.parseDouble中不會異常 if (mer.find()) { long memSize = Integer.parseInt(subMemoryLine.replaceAll("\\D+", "")) ; double mem = (Double.parseDouble(memSize + "")/1024)/1024; NumberFormat nf = new DecimalFormat( "0.0 "); mem = Double.parseDouble(nf.format(mem)); //Log.e(LOG_TAG,"=========mem================ " + mem); return String.valueOf(mem); } } catch (IOException e) { e.printStackTrace(); } return "Unavailable"; } /** * 獲取手機剩余內(nèi)存大小 * @return */ public static String getFreeMemorySize() { try { FileReader fr = new FileReader(FILENAME_PROC_MEMINFO); BufferedReader br = new BufferedReader(fr, 2048); // String memoryLine = br.readLine(); String subMemoryLine = ""; String Line = ""; while ((Line = br.readLine()) != null) { if (Line.contains("MemFree:")){ subMemoryLine = Line.substring(Line.indexOf("MemFree:")); break; } } br.close(); Matcher mer = Pattern.compile("^[0-9]+$").matcher(subMemoryLine.replaceAll("\\D+", "")); //如果為正整數(shù)就說明數(shù)據(jù)正確的,確保在Double.parseDouble中不會異常 if (mer.find()) { long memSize = Integer.parseInt(subMemoryLine.replaceAll("\\D+", "")) ; double mem = (Double.parseDouble(memSize + "")/1024)/1024; NumberFormat nf = new DecimalFormat( "0.0 "); mem = Double.parseDouble(nf.format(mem)); //Log.e(LOG_TAG,"=========mem================ " + mem); return String.valueOf(mem); } } catch (IOException e) { e.printStackTrace(); } return "Unavailable"; }
adb 獲取手機儲存大?。?/p>
命令:adb shell cat /proc/partitions
代碼:
private static final String FILENAME_PROC_EMMCINFO = "/proc/partitions"; /** * 獲取手機儲存大小 * @return */ public static String getEmmcSize() { try { FileReader fr = new FileReader(FILENAME_PROC_EMMCINFO); BufferedReader br = new BufferedReader(fr, 2048); String Line = ""; String EmmcSize = ""; while ((Line = br.readLine()) != null) { if (Line.length() >7 && Line.lastIndexOf(" ") > 0) { if (Line.substring(Line.lastIndexOf(" ") + 1 , Line.length()).equals("mmcblk0")) { EmmcSize = removeAllSpace(Line); break; } } } br.close(); if (EmmcSize.length() >7 ){ EmmcSize = (String) EmmcSize.subSequence(4, EmmcSize.length()-7); Matcher mer = Pattern.compile("^[0-9]+$").matcher(EmmcSize); //如果為正整數(shù)就說明數(shù)據(jù)正確的,確保在Double.parseDouble中不會異常 if (mer.find()) { double mem = (Double.parseDouble(EmmcSize)/1024)/1024; NumberFormat nf = new DecimalFormat( "0.0 "); mem = Double.parseDouble(nf.format(mem)); return String.valueOf(mem); } } return "0"; } catch (IOException e) { e.printStackTrace(); } return "Unavailable"; }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。