當前位置:首頁 » 安卓系統 » android內存讀取

android內存讀取

發布時間: 2024-07-30 07:23:39

⑴ android 怎麼獲取手機內存里的音樂信息

Android自帶的音樂播放器中,在獲取音樂文件信息的時候是通過掃描得到相關信息的。掃描時使用掃描器MediaScanner完成。
Android系統提供了MediaScanner、MediaProvider、MediaStore等介面,並且提供了一套資料庫表格,通過Content Provider的方式提供給用戶。當手機開機或者有SD卡插拔等事件發生時,系統將會自動掃描SD卡和手機內存上的媒體文件,如audio、video、圖片等,將相應的信息放到定義好的資料庫表格中。在這個程序中,我們不需要關心如何去掃描手機中的文件,只要了解如何查詢和使用這些信息就可以了。
MediaStore中定義了一系列的數據表格,通過Android ContentResolver提供的查詢介面,我們可以得到各種需要的信息。下面我們重點介紹查詢SD卡上的音樂文件信息。
先來了解一下ContentResolver的查詢介面:
Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
Uri:指明要查詢的資料庫名稱加上表的名稱,從MediaStore中我們可以找到相應信息的參數。
Projection: 指定查詢資料庫表中的哪幾列,返回的游標中將包括相應的信息。Null則返回所有信息。
selection: 指定查詢條件
selectionArgs:參數selection里有 ?這個符號是,這里可以以實際值代替這個問號。如果selection這個沒有?的話,那麼這個String數組可以為null。
SortOrder:指定查詢結果的排列順序
下面的命令將返回所有在外部存儲卡上的音樂文件的信息:
Cursor cursor = query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
得到cursor後,我們可以調用Cursor的相關方法具體的音樂信息:
歌曲ID:MediaStore.Audio.Media._ID
Int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));
歌曲的名稱:MediaStore.Audio.Media.TITLE
String tilte = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
歌曲的專輯名:MediaStore.Audio.Media.ALBUM
String album = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));

歌曲的歌手名:MediaStore.Audio.Media.ARTIST
String artist = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));

歌曲文件的路徑:MediaStore.Audio.Media.DATA
String url = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
歌曲的總播放時長:MediaStore.Audio.Media.DURATION
Int ration = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));
歌曲文件的大小:MediaStore.Audio.Media.SIZE
Int size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE));

⑵ android 鎬庢牱鑾峰彇褰撳墠apk鎵鍗犵敤鐨勫唴瀛

榪欎釜鏂規硶鏈夊緢澶氾紝甯哥敤鐨勬槸 adb shell mpsys meminfo <package_name> 榪欏彲浠ョ湅鍒版瘮杈冨叏闈㈢殑淇℃伅,鐢變簬Android鏄鏈夊唴瀛樺叡浜鐨勶紝鎵浠ラ氬父鏈 VSS錛孯SS錛孭SS錛孶SS絳変笉鍚岀殑鍐呭瓨琛ㄨ堪錛屾瘮杈冨父鐢ㄧ殑鏄疨SS錛屼細灝嗗叡浜搴撴寜鐓ф瘮渚嬪垎閰嶇粰褰撳墠鍐呭瓨

⑶ Android獲取系統cpu信息,內存,版本,電量等信息

1、CPU頻率,CPU信息:/proc/cpuinfo和/proc/stat

通過讀取文件/proc/cpuinfo系統CPU的類型等多種信息。

讀取/proc/stat 所有CPU活動的信息來計算CPU使用率

下面我們就來講講如何通過代碼來獲取CPU頻率:

復制代碼 代碼如下:

package com.orange.cpu;

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import java.io.InputStream;

public class CpuManager {

// 獲取CPU最大頻率(單位KHZ)

// "/system/bin/cat" 命令行

// "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" 存儲最大頻率的文件的.路徑

public static String getMaxCpuFreq() {

String result = "";

ProcessBuilder cmd;

try {

String[] args = { "/system/bin/cat",

"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" };

cmd = new ProcessBuilder(args);

Process process = cmd.start();

InputStream in = process.getInputStream();

byte[] re = new byte[24];

while (in.read(re) != -1) {

result = result + new String(re);

}

in.close();

} catch (IOException ex) {

ex.printStackTrace();

result = "N/A";

}

return result.trim();

}

// 獲取CPU最小頻率(單位KHZ)

public static String getMinCpuFreq() {

String result = "";

ProcessBuilder cmd;

try {

String[] args = { "/system/bin/cat",

"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq" };

cmd = new ProcessBuilder(args);

Process process = cmd.start();

InputStream in = process.getInputStream();

byte[] re = new byte[24];

while (in.read(re) != -1) {

result = result + new String(re);

}

in.close();

} catch (IOException ex) {

ex.printStackTrace();

result = "N/A";

}

return result.trim();

}

// 實時獲取CPU當前頻率(單位KHZ)

public static String getCurCpuFreq() {

String result = "N/A";

try {

FileReader fr = new FileReader(

"/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq");

BufferedReader br = new BufferedReader(fr);

String text = br.readLine();

result = text.trim();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

return result;

}

// 獲取CPU名字

public static String getCpuName() {

try {

FileReader fr = new FileReader("/proc/cpuinfo");

BufferedReader br = new BufferedReader(fr);

String text = br.readLine();

String[] array = text.split(":s+", 2);

for (int i = 0; i < array.length; i++) {

}

return array[1];

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

return null;

}

}

2、內存:/proc/meminfo

復制代碼 代碼如下:

public void getTotalMemory() {

String str1 = "/proc/meminfo";

String str2="";

try {

FileReader fr = new FileReader(str1);

BufferedReader localBufferedReader = new BufferedReader(fr, 8192);

while ((str2 = localBufferedReader.readLine()) != null) {

Log.i(TAG, "---" + str2);

}

} catch (IOException e) {

}

}

3、Rom大小

復制代碼 代碼如下:

public long[] getRomMemroy() {

long[] romInfo = new long[2];

//Total rom memory

romInfo[0] = getTotalInternalMemorySize();

//Available rom memory

File path = Environment.getDataDirectory();

StatFs stat = new StatFs(path.getPath());

long blockSize = stat.getBlockSize();

long availableBlocks = stat.getAvailableBlocks();

romInfo[1] = blockSize * availableBlocks;

getVersion();

return romInfo;

}

public long getTotalInternalMemorySize() {

File path = Environment.getDataDirectory();

StatFs stat = new StatFs(path.getPath());

long blockSize = stat.getBlockSize();

long totalBlocks = stat.getBlockCount();

return totalBlocks * blockSize;

}

4、sdCard大小

復制代碼 代碼如下:

public long[] getSDCardMemory() {

long[] sdCardInfo=new long[2];

String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {

File sdcardDir = Environment.getExternalStorageDirectory();

StatFs sf = new StatFs(sdcardDir.getPath());

long bSize = sf.getBlockSize();

long bCount = sf.getBlockCount();

long availBlocks = sf.getAvailableBlocks();

sdCardInfo[0] = bSize * bCount;//總大小

sdCardInfo[1] = bSize * availBlocks;//可用大小

}

return sdCardInfo;

}

5、電池電量

復制代碼 代碼如下:

private BroadcastReceiver batteryReceiver=new BroadcastReceiver(){

@Override

public void onReceive(Context context, Intent intent) {

int level = intent.getIntExtra("level", 0);

// level加%就是當前電量了

}

};

registerReceiver(batteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

6、系統的版本信息

復制代碼 代碼如下:

public String[] getVersion(){

String[] version={"null","null","null","null"};

String str1 = "/proc/version";

String str2;

String[] arrayOfString;

try {

FileReader localFileReader = new FileReader(str1);

BufferedReader localBufferedReader = new BufferedReader(

localFileReader, 8192);

str2 = localBufferedReader.readLine();

arrayOfString = str2.split("s+");

version[0]=arrayOfString[2];//KernelVersion

localBufferedReader.close();

} catch (IOException e) {

}

version[1] = Build.VERSION.RELEASE;// firmware version

version[2]=Build.MODEL;//model

version[3]=Build.DISPLAY;//system version

return version;

}

7、mac地址和開機時間

復制代碼 代碼如下:

public String[] getOtherInfo(){

String[] other={"null","null"};

WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);

WifiInfo wifiInfo = wifiManager.getConnectionInfo();

if(wifiInfo.getMacAddress()!=null){

other[0]=wifiInfo.getMacAddress();

} else {

other[0] = "Fail";

}

other[1] = getTimes();

return other;

}

private String getTimes() {

long ut = SystemClock.elapsedRealtime() / 1000;

if (ut == 0) {

ut = 1;

}

int m = (int) ((ut / 60) % 60);

int h = (int) ((ut / 3600));

return h + " " + mContext.getString(R.string.info_times_hour) + m + " "

+ mContext.getString(R.string.info_times_minute);

}

⑷ Android鑾峰彇搴旂敤鍐呭瓨浣跨敤鎯呭喌鐨勬柟娉

  1銆 璇ヤ唬鐮佽幏鍙栧綋鍓嶅簲鐢ㄧ▼搴忕殑鍐呭瓨浣跨敤鎯呭喌ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); //鏈澶у垎閰嶅唴瀛 int memory = activityManager銆
  getMemoryClass(); System銆俹ut銆俻rintln("memory: "+memory); //鏈澶у垎閰嶅唴瀛樿幏鍙栨柟娉2 float maxMemory = (float) (Runtime銆倈etRuntime()銆俶axMemory() * 1銆
  0/ (1024 * 1024)); //褰撳墠鍒嗛厤鐨勬誨唴瀛 float totalMemory = (float) (Runtime銆倈etRuntime()銆倀otalMemory() * 1銆0/ (1024 * 1024)); //鍓╀綑鍐呭瓨 float freeMemory = (float) (Runtime銆
  getRuntime()銆俧reeMemory() * 1銆0/ (1024 * 1024)); System銆俹ut銆俻rintln("maxMemory: "+maxMemory); System銆俹ut銆俻rintln("totalMemory: "+totalMemory); System銆
  out銆俻rintln("freeMemory: "+freeMemory);緇撴灉System銆俹ut: memory: 256System銆俹ut: maxMemory: 256銆0System銆俹ut: totalMemory: 11銆974937System銆
  out: freeMemory: 3銆6257935榪欒〃鏄庢垜鐨勫簲鐢ㄧ▼搴忓湪褰撳墠鎵嬫満涓婄殑鏈澶у垎閰嶅唴瀛樹負256m錛岀幇鍦ㄥ凡鍒嗛厤11m錛岃11m涓鐨6m鏄鍏嶈垂鐨勫綋鐒訛紝鎮ㄥ彲浠ラ氳繃Monitors鏇寸洿瑙傚湴鏌ョ湅鍐呭瓨浣跨敤鎯呭喌2銆 浣跨敤dos鍛戒護錛1錛夋墦寮dos紿楀彛騫舵墽琛宎db shell錛2錛塪umpsys meminfo杞浠跺寘鍚嶇О緇撴灉:3銆
   浣跨敤鏄劇ず鍣ㄦ垨DDMS鏄劇ず鍣―DMS銆

⑸ 如何獲取android系統總的內存容量

在設置-存儲那裡就可以看到了,會顯示存儲設置的SD卡和內部存儲空間的容量,要是運存的話可以看看設置-關於手機那裡

熱點內容
華為手機怎麼密碼解鎖 發布:2024-11-25 17:56:34 瀏覽:938
伺服器管理員怎麼編輯別人背包 發布:2024-11-25 17:55:45 瀏覽:930
plc編程T 發布:2024-11-25 17:55:02 瀏覽:268
資料庫年薪 發布:2024-11-25 17:51:18 瀏覽:666
王者榮耀如何給賬號設置密碼 發布:2024-11-25 17:36:48 瀏覽:759
以巧克力為主寫一篇腳本 發布:2024-11-25 17:16:59 瀏覽:335
資料庫課時 發布:2024-11-25 16:57:50 瀏覽:451
dns伺服器名稱地址 發布:2024-11-25 16:57:49 瀏覽:932
如何給監控加訪問密碼 發布:2024-11-25 16:45:13 瀏覽:601
國外安卓音樂播放器哪個好 發布:2024-11-25 16:35:58 瀏覽:143