獲取手機的相關資訊
-
package com.ransj.tool;
-
import java.io.BufferedReader;
-
import java.io.FileNotFoundException;
-
import java.io.FileReader;
-
import java.io.IOException;
-
import java.io.ObjectInputStream.GetField;
-
import android.Manifest;
-
import android.app.Activity;
-
import android.app.ActivityManager;
-
import android.app.ActivityManager.MemoryInfo;
-
import android.content.Context;
-
import android.content.pm.PackageManager;
-
import android.net.ConnectivityManager;
-
import android.net.NetworkInfo;
-
import android.os.Build;
-
import android.telephony.TelephonyManager;
-
import android.util.Log;
-
/**
-
* retrieve phone info
-
*
-
*
-
*/
-
public class PhoneInfo {
-
private static final String TAG = PhoneInfo.class.getSimpleName();
-
private static final String FILE_MEMORY = "/proc/meminfo";
-
private static final String FILE_CPU = "/proc/cpuinfo";
-
public String mIMEI;
-
public int mPhoneType;
-
public int mSysVersion;
-
public String mNetWorkCountryIso;
-
public String mNetWorkOperator;
-
public String mNetWorkOperatorName;
-
public int mNetWorkType;
-
public boolean mIsOnLine;
-
public String mConnectTypeName;
-
public long mFreeMem;
-
public long mTotalMem;
-
public String mCupInfo;
-
public String mProductName;
-
public String mModelName;
-
public String mManufacturerName;
-
/**
-
* private constructor
-
*/
-
private PhoneInfo() {
-
}
-
/**
-
* get imei
-
*
-
* @return
-
*/
-
public static String getIMEI(Context context) {
-
TelephonyManager manager = (TelephonyManager) context
-
.getSystemService(Activity.TELEPHONY_SERVICE);
-
// check if has the permission
-
if (PackageManager.PERMISSION_GRANTED == context.getPackageManager()
-
.checkPermission(Manifest.permission.READ_PHONE_STATE,
-
context.getPackageName())) {
-
return manager.getDeviceId();
-
} else {
-
return null;
-
}
-
}
-
/**
-
* get phone type,like :GSM��CDMA��SIP��NONE
-
*
-
* @param context
-
* @return
-
*/
-
public static int getPhoneType(Context context) {
-
TelephonyManager manager = (TelephonyManager) context
-
.getSystemService(Activity.TELEPHONY_SERVICE);
-
return manager.getPhoneType();
-
}
-
/**
-
* get phone sys version
-
*
-
* @return
-
*/
-
public static int getSysVersion() {
-
return Build.VERSION.SDK_INT;
-
}
-
/**
-
* Returns the ISO country code equivalent of the current registered
-
* operator's MCC (Mobile Country Code).
-
*
-
* @param context
-
* @return
-
*/
-
public static String getNetWorkCountryIso(Context context) {
-
TelephonyManager manager = (TelephonyManager) context
-
.getSystemService(Activity.TELEPHONY_SERVICE);
-
return manager.getNetworkCountryIso();
-
}
-
/**
-
* Returns the numeric name (MCC+MNC) of current registered operator.may not
-
* work on CDMA phone
-
*
-
* @param context
-
* @return
-
*/
-
public static String getNetWorkOperator(Context context) {
-
TelephonyManager manager = (TelephonyManager) context
-
.getSystemService(Activity.TELEPHONY_SERVICE);
-
return manager.getNetworkOperator();
-
}
-
/**
-
* Returns the alphabetic name of current registered operator.may not work
-
* on CDMA phone
-
*
-
* @param context
-
* @return
-
*/
-
public static String getNetWorkOperatorName(Context context) {
-
TelephonyManager manager = (TelephonyManager) context
-
.getSystemService(Activity.TELEPHONY_SERVICE);
-
return manager.getNetworkOperatorName();
-
}
-
/**
-
* get type of current network
-
*
-
* @param context
-
* @return
-
*/
-
public static int getNetworkType(Context context) {
-
TelephonyManager manager = (TelephonyManager) context
-
.getSystemService(Activity.TELEPHONY_SERVICE);
-
return manager.getNetworkType();
-
}
-
/**
-
* is webservice aviliable
-
*
-
* @param context
-
* @return
-
*/
-
public static boolean isOnline(Context context) {
-
ConnectivityManager manager = (ConnectivityManager) context
-
.getSystemService(Activity.CONNECTIVITY_SERVICE);
-
NetworkInfo info = manager.getActiveNetworkInfo();
-
if (info != null && info.isConnected()) {
-
return true;
-
}
-
return false;
-
}
-
/**
-
* get current data connection type name ,like ,Mobile��WIFI��OFFLINE
-
*
-
* @param context
-
* @return
-
*/
-
public static String getConnectTypeName(Context context) {
-
if (!isOnline(context)) {
-
return "OFFLINE";
-
}
-
ConnectivityManager manager = (ConnectivityManager) context
-
.getSystemService(Activity.CONNECTIVITY_SERVICE);
-
NetworkInfo info = manager.getActiveNetworkInfo();
-
if (info != null) {
-
return info.getTypeName();
-
} else {
-
return "OFFLINE";
-
}
-
}
-
/**
-
* get free memory of phone, in M
-
*
-
* @param context
-
* @return
-
*/
-
public static long getFreeMem(Context context) {
-
ActivityManager manager = (ActivityManager) context
-
.getSystemService(Activity.ACTIVITY_SERVICE);
-
MemoryInfo info = new MemoryInfo();
-
manager.getMemoryInfo(info);
-
long free = info.availMem / 1024 / 1024;
-
return free;
-
}
-
/**
-
* get total memory of phone , in M
-
*
-
* @param context
-
* @return
-
*/
-
public static long getTotalMem(Context context) {
-
try {
-
FileReader fr = new FileReader(FILE_MEMORY);
-
BufferedReader br = new BufferedReader(fr);
-
String text = br.readLine();
-
String[] array = text.split("\\s+");
-
Log.w(TAG, text);
-
return Long.valueOf(array[1]) / 1024;
-
} catch (FileNotFoundException e) {
-
e.printStackTrace();
-
} catch (IOException e) {
-
e.printStackTrace();
-
}
-
return -1;
-
}
-
public static String getCpuInfo() {
-
try {
-
FileReader fr = new FileReader(FILE_CPU);
-
BufferedReader br = new BufferedReader(fr);
-
String text = br.readLine();
-
String[] array = text.split(":\\s+", 2);
-
for (int i = 0; i < array.length; i++) {
-
Log.w(TAG, " ..... " + array[i]);
-
}
-
Log.w(TAG, text);
-
return array[1];
-
} catch (FileNotFoundException e) {
-
e.printStackTrace();
-
} catch (IOException e) {
-
相關推薦
使用gethostname()函式和gethostbyname()函式獲取主機相關資訊
gethostname():返回本地主機的標準主機名 原型如下: #include <unistd.h> int gethostname(char *name, size_t len); 引數說明: 這個函式需要兩個引數: 接收緩衝區name,其長度必須為len位元組或是更長
Android 獲取手機儲存資訊詳解(記憶體,外存等)
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); //系統記憶體資訊 ActivityManager.MemoryInfo memInfo = new ActivityManager
JS獲取 URL相關資訊,引數
Location 物件包含有關當前 URL 的資訊。 Location 物件是 Window 物件的一個部分,可通過 window.location 屬性來訪問。 hash 設定或返回從井號 (
請教一個能在WinPE環境下獲取系統相關資訊的程式碼
來上海將近2年了,然而我已經換過了3家公司,也許很多人都很懵逼,這也太頻繁了吧!你有啥不滿足的?我想如果是一個面試官,一聽2年內換3家 ,肯定是不想要這個人的。所以我在面試第四家的時候,我就把我第三家的工作經歷去掉了,沒寫第三家,也許有人會站在道德的制高點說我了,說我造假什麼
iOS開發-Object-C獲取手機裝置資訊(UIDevice)
一、獲取UiDevice裝置資訊 // 獲取裝置名稱 NSString *name = [[UIDevice currentDevice] name]; // 獲取裝置系統名稱 NSString *systemName = [[UIDevice currentDevice] systemName
android-獲取手機小區資訊介面設計
1. manifests <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package
獲取數字證書相關資訊,證書有效性驗證,RSA加密和解密功能之獲取證書相關資訊
//公鑰 private PublicKey pk; /** 後臺將證書以byte陣列的形式傳入 * @param bytes,數字證書crt傳入的byte陣列 * @return */ public InfoEntity getCertificateInfo(
Android如何獲取手機各項資訊
1、使用Build獲取架構屬性 下面我們來根據原始碼看看通過Build這個類可以得到哪些配置資訊,具體就不解釋了,從命名基本可以理解其代表的屬性。 public class Build { //當一個版本屬性不知道時所設定的值。 publ
ABPeoplePickerNavigationController 獲取手機通訊錄資訊
最近專案用到獲取使用者手機通訊錄的功能,但發現有兩個代理方法在iOS 9.0 廢棄了,用新的代理方法代替,所以整理下供以後參考。。 #pragma mark - 點選聯絡人 連結到使用者手機通訊錄 - (void)accessPhoneBook: (UIButton *)
Android使用NotificationListenerService獲取通知相關資訊
前言 我們可能需要監聽通知欄,來獲取系統通知,然後去得到通知的相關資訊,或者我們可能需要知道某一個通知是否處於活動狀態還是已經被使用者處理了! 概況 在Android4.4之前,我們更多的是通過反射來獲取通知的相關資訊!NotificationList
原生js獲取手機定位資訊
<script type="text/javascript"> function Location() {}; Location.prototype.getLocation = function (callback) { var options = {
獲取手機聯絡人資訊 很簡單的方法
String a; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.la
獲取裝置相關資訊工具包
拿走不謝 在使用springboot獲取螢幕引數時,可能會報關於headless為NULL的錯誤,不要慌,這樣來:只需要在啟動的application中替換main函式內容為: @SpringBootApplication public class Ad
android--------根據檔案路徑使用File類獲取檔案相關資訊
Android通過檔案路徑如何得到檔案相關資訊,如 檔名稱,檔案大小,建立時間,檔案的相對路徑,檔案的絕對路徑等。如圖:public class MainActivity extends Activity { private String path = "/storage
Android獲取手機基站資訊並進行基站定位(基站定位原理)
http://blog.csdn.net/mad1989/article/details/9970431 一,首先普及一下手機基站資訊中相關的專業詞彙: 通過TelephonyManager 獲取lac:mcc:mnc:cell-id(基站資訊)的解釋: MCC,M
Android 獲取手機儲存資訊詳解(記憶體,外存等)
android 獲取手機儲存資訊詳解(記憶體,外存等) android不像ios,android可以外接Sd卡,並且也會有內接的儲存卡,此次專門研究下如何獲取android的儲存資訊。 一、RAM記憶體 RAM,也就是我們常說的手機記憶體。最早的記憶體大小
iOS獲取裝置相關資訊
UIDevice *device = [UIDevicenew]; NSLog(@"%@ %@ %@ %@ %@",device.name,device.model,device.localizedModel,device.systemName,device.syste
獲取手機品牌資訊的Build類
一、需求 Build類獲取手機制造商,系統定製商,型號,Android 系統版本,CPU 指令集,可以檢視是否支援64位等 二、原始碼 // // Source code recreated from a .class file by Intell
如何使用ADB命令檢視Android手機相關資訊引數
本文主要介紹的是教大家如何使用ADB命令來檢視自己Android手機的相關硬體以及其他的引數資訊,相信許多機友已經早已檢視過,而新入門感興趣的機友可以嘗試一下…… 本文主要介紹的是教大家如何使用ADB命令來檢視自己手機的相關硬體以及其他的引數資訊,相信許多機友已經早
Android ContentResolver ContactsContract 獲取手機聯絡人資訊
獲取手機聯絡人資訊步驟: 1、獲取 ContentResolver ContentResolver resolver = getContentResolver(); 2、resolver.query(*)查詢資訊 查詢手機聯絡人的URI:Cont