当前位置:操作系统 > 安卓/Android >>

Android 获取手机信息

[java]  
/** 
     * 获取手机信息 
     */  
    public void getPhoneInfo()  
    {  
        TelephonyManager tm = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);  
        String mtyb = android.os.Build.BRAND;// 手机品牌   
        String mtype = android.os.Build.MODEL; // 手机型号   
        String imei = tm.getDeviceId();  
        String imsi = tm.getSubscriberId();  
        String numer = tm.getLine1Number(); // 手机号码   
        String serviceName = tm.getSimOperatorName(); // 运营商   
        tvPhoneInfo.setText("品牌: " + mtyb + "\n" + "型号: " + mtype + "\n" + "版本: Android " + android.os.Build.VERSION.RELEASE + "\n" + "IMEI: " + imei  
                + "\n" + "IMSI: " + imsi + "\n" + "手机号码: " + numer + "\n" + "运营商: " + serviceName + "\n");  
    }  
 
/**
* 获取手机信息
*/
public void getPhoneInfo()
{
TelephonyManager tm = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);
String mtyb = android.os.Build.BRAND;// 手机品牌
String mtype = android.os.Build.MODEL; // 手机型号
String imei = tm.getDeviceId();
String imsi = tm.getSubscriberId();
String numer = tm.getLine1Number(); // 手机号码
String serviceName = tm.getSimOperatorName(); // 运营商
tvPhoneInfo.setText("品牌: " + mtyb + "\n" + "型号: " + mtype + "\n" + "版本: Android " + android.os.Build.VERSION.RELEASE + "\n" + "IMEI: " + imei
+ "\n" + "IMSI: " + imsi + "\n" + "手机号码: " + numer + "\n" + "运营商: " + serviceName + "\n");
}
 
 
 
[java]  
/** 
     * 获取手机内存大小 
     *  
     * @return 
     */  
    private String 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");  
            }  
  
            initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024;// 获得系统总内存,单位是KB,乘以1024转换为Byte   
            localBufferedReader.close();  
  
        }  
        catch (IOException e)  
        {  
        }  
        return Formatter.formatFileSize(getBaseContext(), initial_memory);// Byte转换为KB或者MB,内存大小规格化   
    }  
 
/**
* 获取手机内存大小
* @return
*/
private String 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");
}
 
initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024;// 获得系统总内存,单位是KB,乘以1024转换为Byte
localBufferedReader.close();
 
}
catch (IOException e)
{
}
return Formatter.formatFileSize(getBaseContext(), initial_memory);// Byte转换为KB或者MB,内存大小规格化
}
[java] 
/** 
 * 获取当前可用内存大小 
 *  
 * @return 
 */  
private String getAvailMemory()  
{  
    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);  
    MemoryInfo mi = new MemoryInfo();  
    am.getMemoryInfo(mi);  
    return Formatter.formatFileSize(getBaseContext(), mi.availMem);  
}  
 
/**
* 获取当前可用内存大小
* @return
*/
private String getAvailMemory()
{
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
MemoryInfo mi = new MemoryInfo();
am.getMemoryInfo(mi);
return Formatter.formatFileSize(getBaseContext(), mi.availMem);
}
 
 
 
 
[java]  
/** 
     * 获取手机CPU信息 
     *  
     * @return 
     */  
    public String[] getCpuInfo()  
    {  
        String str1 = "/proc/cpuinfo";  
        String str2 = "";  
        String[] cpuInfo = { "", "" };  
        String[] arrayOfString;  
        try  
        {  
            FileReader fr = new FileReader(str1);  
         
补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,