相对于Iphone来说Android平台开放得多,很多有关设备和SIM卡的信息都能得到,下面列出一些常用的信息,方便以后查找。
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String tmDevice, tmSerial, androidId;
tmDevice = “” + tm.getDeviceId();
tmSerial = “” + tm.getSimSerialNumber();
androidId = “” + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
String id = deviceUuid.toString(); // 设备ID
String imsi = tm.getSubscriberId(); // imsi
String phone = tm.getLine1Number(); // 手机号码 可能为空字符串(“”)
String model = Build.MODEL; // 手机型号
WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wm.getConnectionInfo();
String mac = wifiInfo.getMacAddress(); // 网卡地址 可能为null
String country = tm.getSimCountryIso(); // SIM 国家代码
int app = 0;
try {
PackageInfo paInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
app = paInfo.versionCode; // 应用版本号
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String os = Build.VERSION.RELEASE; // os版本号
String sLanguage = Locale.getDefault().getLanguage(); // 语言环境,中文:zh, 日文:ja, 英文:en
String sNetwork = null;
ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = manager.getActiveNetworkInfo();
if (info != null && info.isConnected()) //是否连接网络
{
//联网方式
if(info.getType() == ConnectivityManager.TYPE_MOBILE)
sNetwork = “3G”;
else if(info.getType() == ConnectivityManager.TYPE_WIFI)
sNetwork = “wifi”;
}
有些SIM卡的号码得不到,是因为这些卡没有把号码写到卡里,但是有imsi能把卡区别开,有时候手机丢了,能换卡不换号,就是因为有imsi。
最后千万不要忘了加权限:
<uses-permission android:name=”android.permission.INTERNET”></uses-permission>
<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”/>
<uses-permission android:name=”android.permission.READ_PHONE_STATE”/>
<uses-permission android:name=”android.permission.ACCESS_WIFI_STATE”/>
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String tmDevice, tmSerial, androidId;
tmDevice = “” + tm.getDeviceId();
tmSerial = “” + tm.getSimSerialNumber();
androidId = “” + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
String id = deviceUuid.toString(); // 设备ID
String imsi = tm.getSubscriberId(); // imsi
String phone = tm.getLine1Number(); // 手机号码 可能为空字符串(“”)
String model = Build.MODEL; // 手机型号
WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wm.getConnectionInfo();
String mac = wifiInfo.getMacAddress(); // 网卡地址 可能为null
String country = tm.getSimCountryIso(); // SIM 国家代码
int app = 0;
try {
PackageInfo paInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
app = paInfo.versionCode; // 应用版本号
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String os = Build.VERSION.RELEASE; // os版本号
String sLanguage = Locale.getDefault().getLanguage(); // 语言环境,中文:zh, 日文:ja, 英文:en
String sNetwork = null;
ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = manager.getActiveNetworkInfo();
if (info != null && info.isConnected()) //是否连接网络
{
//联网方式
if(info.getType() == ConnectivityManager.TYPE_MOBILE)
sNetwork = “3G”;
else if(info.getType() == ConnectivityManager.TYPE_WIFI)
sNetwork = “wifi”;
}
有些SIM卡的号码得不到,是因为这些卡没有把号码写到卡里,但是有imsi能把卡区别开,有时候手机丢了,能换卡不换号,就是因为有imsi。
最后千万不要忘了加权限:
<uses-permission android:name=”android.permission.INTERNET”></uses-permission>
<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”/>
<uses-permission android:name=”android.permission.READ_PHONE_STATE”/>
<uses-permission android:name=”android.permission.ACCESS_WIFI_STATE”/>