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" />
다음은 효과 보기:읽 어 주 셔 서 감사합니다. 여러분 에 게 도움 이 되 기 를 바 랍 니 다.본 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Bitrise에서 배포 어플리케이션 설정 테스트하기이 글은 Bitrise 광고 달력의 23일째 글입니다. 자체 또는 당사 등에서 Bitrise 구축 서비스를 사용합니다. 그나저나 며칠 전 Bitrise User Group Meetup #3에서 아래 슬라이드를 발표했...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.