Android 휴대 전화 정보 획득 실례 상세 설명

안 드 로 이 드 핸드폰 정보 가 져 오기
응용 정보:가방 이름,버 전 번호,버 전 이름,핸드폰 에 루트 권한 이 있 는 지 여부
핸드폰 정보:핸드폰 화면 너비 와 높이,현재 사용 가능 한 메모리 크기,총 메모리 크기,IMEI 번호,IESI 번호,핸드폰 모델,핸드폰 브랜드,핸드폰 MacAdd,CPU 모델,CPU 주파수
단도직입적으로 다음은 자바 코드 이 고 XML 에는 TextView 만 정 보 를 표시 합 니 다.



package com.example.getphoneinfo; 
 
import java.io.BufferedReader; 
import java.io.File; 
import java.io.FileReader; 
import java.io.IOException; 
 
import android.app.Activity; 
import android.content.Context; 
import android.net.wifi.WifiInfo; 
import android.net.wifi.WifiManager; 
import android.os.Bundle; 
import android.os.Environment; 
import android.os.StatFs; 
import android.telephony.TelephonyManager; 
import android.text.format.Formatter; 
import android.view.Menu; 
import android.widget.TextView; 
 
public class MainActivity extends Activity { 
 
  TextView mPhoneInfo; 
  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
     
    initView(); 
    initData(); 
     
  } 
 
  private void initData() { 
    // TODO Auto-generated method stub 
    getAvailMemory();//            
    getTotalMemory();//        
    getHeightAndWidth();//       
    getInfo();//  IMEI ,IESI ,      
    getMacAddress();//  IMEI ,IESI ,      
    getCpuInfo();//  CPU   
    getPackage();//      ,   ,    
    isRoot();//    root 
    String text = getHeightAndWidth() + 
        "
" + getTotalMemory() + "
" + getAvailMemory() + "
" + getInfo() + "
" + getMacAddress() + "
" + getCpuInfo() + "
" + getPackage() + "
" + isRoot(); mPhoneInfo.setText(text); } /** * , , */ private String getPackage(){ try { String pkName = this.getPackageName(); String versionName = this.getPackageManager().getPackageInfo( pkName, 0).versionName; int versionCode = this.getPackageManager() .getPackageInfo(pkName, 0).versionCode; return "Package:" + pkName + "
versionName:" + versionName + "
versionCode:" + versionCode; } catch (Exception e) { } return null; } /** * root * @return */ private String isRoot(){ String bool = "Root:false"; try{ if ((!new File("/system/bin/su").exists()) && (!new File("/system/xbin/su").exists())){ bool = "Root:false"; } else { bool = "Root:true"; } } catch (Exception e) { } return bool; } /** * android */ private String getAvailMemory() {// android File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return " :" + Formatter.formatFileSize(MainActivity.this, blockSize * availableBlocks); } /** * */ 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+"); 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 */ public String getHeightAndWidth(){ int width=getWindowManager().getDefaultDisplay().getWidth(); int heigth=getWindowManager().getDefaultDisplay().getHeight(); String str = "Width:" + width+"
Height:"+heigth+""; return str; } /** * IMEI ,IESI , */ private String getInfo() { TelephonyManager mTm = (TelephonyManager)this.getSystemService(TELEPHONY_SERVICE); String imei = mTm.getDeviceId(); String imsi = mTm.getSubscriberId(); String mtype = android.os.Build.MODEL; // String mtyb= android.os.Build.BRAND;// String numer = mTm.getLine1Number(); // , , return " IMEI :"+imei+"
IESI :"+imsi+"
:"+mtype+"
:"+mtyb+"
"+numer; } /** * MAC * wifi mac */ private String getMacAddress(){ String result = ""; WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); result = wifiInfo.getMacAddress(); return " macAdd:" + result; } /** * CPU */ private String getCpuInfo() { String str1 = "/proc/cpuinfo"; String str2 = ""; String[] cpuInfo = {"", ""}; //1-cpu //2-cpu String[] arrayOfString; try { FileReader fr = new FileReader(str1); BufferedReader localBufferedReader = new BufferedReader(fr, 8192); str2 = localBufferedReader.readLine(); arrayOfString = str2.split("\\s+"); for (int i = 2; i < arrayOfString.length; i++) { cpuInfo[0] = cpuInfo[0] + arrayOfString[i] + " "; } str2 = localBufferedReader.readLine(); arrayOfString = str2.split("\\s+"); cpuInfo[1] += arrayOfString[2]; localBufferedReader.close(); } catch (IOException e) { } return "CPU :" + cpuInfo[0] + "
CPU :" + cpuInfo[1]; } public void initView() { // TODO Auto-generated method stub mPhoneInfo = (TextView)findViewById(R.id.id_tv_phone_info); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
메모:권한 추가





<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />  
  <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 

다음은 효과 보기:

읽 어 주 셔 서 감사합니다. 여러분 에 게 도움 이 되 기 를 바 랍 니 다.본 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!

좋은 웹페이지 즐겨찾기