Android获取手机和系统版本等信息的代码
phoneInfo += ", CPU_ABI: " + android.os.Build.CPU_ABI;
phoneInfo += ", TAGS: " + android.os.Build.TAGS;
phoneInfo += ", VERSION_CODES.BASE: " + android.os.Build.VERSION_CODES.BASE;
phoneInfo += ", MODEL: " + android.os.Build.MODEL;
phoneInfo += ", SDK: " + android.os.Build.VERSION.SDK;
phoneInfo += ", VERSION.RELEASE: " + android.os.Build.VERSION.RELEASE;
phoneInfo += ", DEVICE: " + android.os.Build.DEVICE;
phoneInfo += ", DISPLAY: " + android.os.Build.DISPLAY;
phoneInfo += ", BRAND: " + android.os.Build.BRAND;
phoneInfo += ", BOARD: " + android.os.Build.BOARD;
phoneInfo += ", FINGERPRINT: " + android.os.Build.FINGERPRINT;
phoneInfo += ", ID: " + android.os.Build.ID;
phoneInfo += ", MANUFACTURER: " + android.os.Build.MANUFACTURER;
phoneInfo += ", USER: " + android.os.Build.USER;
// Toast.makeText(this, phoneInfo, Toast.LENGTH_LONG).show();
TextView t = (TextView) findViewById(R.id.main_phoneinfo);
t.setText(phoneInfo);
TelephonyManager tm = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);
tm.getNetworkType();//int
/*
* 当前使用的网络类型:
* 例如: NETWORK_TYPE_UNKNOWN 网络类型未知 0
NETWORK_TYPE_GPRS GPRS网络 1
NETWORK_TYPE_EDGE EDGE网络 2
NETWORK_TYPE_UMTS UMTS网络 3
NETWORK_TYPE_HSDPA HSDPA网络 8
NETWORK_TYPE_HSUPA HSUPA网络 9
NETWORK_TYPE_HSPA HSPA网络 10
NETWORK_TYPE_CDMA CDMA网络,IS95A 或 IS95B. 4
NETWORK_TYPE_EVDO_0 EVDO网络, revision 0. 5
NETWORK_TYPE_EVDO_A EVDO网络, revision A. 6
NETWORK_TYPE_1xRTT 1xRTT网络 7
*/
Android开发平台中,可通过TelephonyManager 获取本机号码。
txtPhoneNumber.setText(phoneMgr.getLine1Number()); //txtPhoneNumber是一个EditText 用于显示手机号
注:
根 据Android的安全机制,在使用TelephonyManager时,必须在AndroidManifest.xml中添加<uses- permission android:name="READ_PHONE_STATE" /> 否则无法获得系统的许可。
手机型号 Build.MODEL
String | MODEL | The end-user-visible name for the end product. |
sdk版本 Build.VERSION.SDK
String | SDK | This constant is deprecated. Use SDK_INT to easily get this as an integer. |
及frimware版本号(系统版本号) Build.VERSION.RELEASE
String | RELEASE | The user-visible version string. |
{
TelephonyManager phoneMgr=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
txtPhoneModel.setText(Build.MODEL); //手机型号
txtPhoneNumber.setText(phoneMgr.getLine1Number());//本机电话号码
txtSdkVersion.setText(Build.VERSION.SDK);//SDK版本号
txtOsVersion.setText(Build.VERSION.RELEASE);//Firmware/OS 版本号
}
事实上,Build能向我们提供包括 硬件厂商,硬件编号,序列号等很多信息 调用方法也都同上,很简单。
String | BOARD | The name of the underlying board, like "goldfish". |
String | BOOTLOADER | The system bootloader version number. |
String | BRAND | The brand (e.g., carrier) the software is customized for, if any. |
String | CPU_ABI | The name of the instruction set (CPU type + ABI convention) of native code. |
String | CPU_ABI2 | The name of the second instruction set (CPU type + ABI convention) of native code. |
String | DEVICE | The name of the industrial design. |
String | DISPLAY | A build ID string meant for displaying to the user |
String | FINGERPRINT | A string that uniquely identifies this build. |
String | HARDWARE | The name of the hardware (from the kernel command line or /proc). |
String | HOST | |
String | ID | Either a changelist number, or a label like "M4-rc20". |
String | MANUFACTURER | The manufacturer of the product/hardware. |
String | MODEL | The end-user-visible name for the end product. |
String | PRODUCT | The name of the overall product. |
String | RADIO | The radio firmware version number. |
String | SERIAL | A hardware serial number, if available. |
String | TAGS | Comma-separated tags describing the build, like "unsigned,debug". |
long | TIME | |
String | TYPE | The type of build, like "user" or "eng". |
String | UNKNOWN | Value used for when a build property is unknown. |
String | USER |
最近在做韩国一家公司的Android平台软件开发,我的手机号是韩国的啦。所以看到010打头的号码,别太惊讶..
在做手机软件客户端开发的过程中,连网模块基本是不可以缺少,除非是做单击版本的游戏之类的开发。其中获取手机设置的连网方式是一个很重要的方 式,除了 j2me平台,其它平台基本都可以通过系统提供的接口获得,这个也j2me的短板,比如如果你的真机设置的连网方式和你代码的连网方式不一致的时候s40 手机是连不上网络的,所以一般的网络模块都会有自动切换接入方式的功能,自动切换是通过先net或者wap失败了再切换值wap或者net方式去连网,所 以你在用s40手机连网的时候第一次很慢可能就是这个原因了。在Android平台下提供了很全面的网络接口,获取手机设置的网络接入方式更是不在话下 了,所以开发以来很方便。
Activity提供了获取网络管理类的接口ConnectivityManager,用ConnectivityManager就可获取网络信息类NetworkInfo,NetworkInfo包含了很多网络状况的信息。如下代码实例:
ConnectivityManager cm = (ConnectivityManager) act.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
String typeName = info.getTypeName(); //cmwap/cmnet/wifi/uniwap/uninet