這個功能實現的是獲取用戶手機的一些定義的信息java
package lovefang.stadyService; /**引入包*/ import android.os.Bundle; import android.app.Activity; import android.app.Service; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.content.ContentResolver;//This class provides applications access to the content model. import android.telephony.TelephonyManager; import android.util.Log; /**獲取手機的狀態*/ public class UsePhoneState extends Activity{ /**建立參數*/ private ContentResolver cr; private Button getStateButton;// 用來獲取用戶的手機狀態 /**建立Activity*/ public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.usephonestate); cr = getContentResolver(); Log.v("UsePhonestate","cr = getContentResolver()"); Log.v("UsePhonestate","setContentView"); getStateButton = (Button) findViewById(R.id.button_getphonestate); Log.v("UsePhonestate","getStateButton"); getStateButton.setOnClickListener(getState); Log.v("UsePhonestate","getStateButton.setOnClickListener"); } private Button.OnClickListener getState = new Button.OnClickListener(){ public void onClick(View view){ /**得到TelephonyManager對象*/ TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Service.TELEPHONY_SERVICE); /**獲取電信網絡級別*/ String teleCode = telephonyManager.getNetworkCountryIso(); /**獲取電信網絡公司代碼*/ String teleComCode = telephonyManager.getNetworkOperator(); /**獲取電信網絡公司名稱*/ String teleComName = telephonyManager.getNetworkOperatorName(); /**獲取行動通訊類型*/ int TypeCode = telephonyManager.getPhoneType(); String type = ""; switch(TypeCode){ case TelephonyManager.PHONE_TYPE_NONE: type = "PHONE_TYPE_NONE"; break; case TelephonyManager.PHONE_TYPE_GSM: type = "PHONE_TYPE_GSM"; break; case TelephonyManager.PHONE_TYPE_CDMA: type = "PHONE_TYPE_CDMA"; break; } /**獲取網絡類型*/ int netTypeCode = telephonyManager.getNetworkType(); String netType = "NETWORK_TYPE_UNKNOW"; switch(netTypeCode){ case TelephonyManager.NETWORK_TYPE_1xRTT: netType = "NETWORK_TYPE_1xRTT"; break; case TelephonyManager.NETWORK_TYPE_CDMA: netType = "NETWORK_TYPE_CDMA"; break; case TelephonyManager.NETWORK_TYPE_EDGE: netType = "NETWORK_TYPE_EDGE"; break; case TelephonyManager.NETWORK_TYPE_EVDO_0: netType = "NETWORK_TYPE_EVDO_0"; break; case TelephonyManager.NETWORK_TYPE_EVDO_A: netType = "NETWORK_TYPE_EVDO_A"; break; case TelephonyManager.NETWORK_TYPE_GPRS: netType = "NETWORK_TYPE_GPRS"; break; case TelephonyManager.NETWORK_TYPE_HSDPA: netType = "NETWORK_TYPE_HSDPA"; break; case TelephonyManager.NETWORK_TYPE_HSPA: netType = "NETWORK_TYPE_HSPA"; break; case TelephonyManager.NETWORK_TYPE_HSUPA: netType = "NETWORK_TYPE_HSUPA"; break; case TelephonyManager.NETWORK_TYPE_IDEN: netType = "NETWORK_TYPE_IDEN"; break; case TelephonyManager.NETWORK_TYPE_UMTS: netType = "NETWORK_TYPE_UMTS"; break; default: break; } /**獲取漫遊狀態*/ boolean roamStatusCode = telephonyManager.isNetworkRoaming(); String roamStatus = "NOT ROAMINF"; if(roamStatusCode){ roamStatus = "ROAMING"; } /**獲取手機惟一標識*/ String imei = telephonyManager.getDeviceId(); /**獲取手機IMEI SV*/ String imeiSV = telephonyManager.getDeviceSoftwareVersion(); /**獲取手機IMSI*/ String imsi = telephonyManager.getSubscriberId(); /**藍牙服務*/ String statusCode = android.provider.Settings.System.getString(cr, android.provider.Settings.System.BLUETOOTH_ON); String bulettothStatus = ""; if(statusCode.equals("1")){ bulettothStatus = "ENABLE"; }else{ bulettothStatus = "DISABLE"; } /**飛行模式是否打開*/ statusCode = android.provider.Settings.System.getString(cr, android.provider.Settings.System.AIRPLANE_MODE_ON); String AirplaneStatus = ""; if(statusCode.equals("1")){ AirplaneStatus = "ENABLE"; }else{ AirplaneStatus = "DISABLE"; } /**數據漫遊模式是否打開*/ statusCode = android.provider.Settings.System.getString(cr, android.provider.Settings.System.DATA_ROAMING); String dataRoamStatus = ""; if(statusCode.equals("1")){ dataRoamStatus = "ENABLE"; }else{ dataRoamStatus = "DISABLE"; } TextView txt = (TextView) findViewById(R.id.text_showphonestate); StringBuilder sb = new StringBuilder(); sb.append("teleCode: "+teleCode+"\n"); sb.append("teleComCode: "+teleComCode+"\n"); sb.append("teleComName: "+teleComName+"\n"); sb.append("type: "+type+"\n"); sb.append("netType: "+netType+"\n"); sb.append("roamStatus: "+roamStatus+"\n"); sb.append("imei: "+imei+"\n"); sb.append("imeiSV: "+imeiSV+"\n"); sb.append("imsi: "+imsi+"\n"); sb.append("bulettothStatus: "+bulettothStatus+"\n"); sb.append("AirplaneStatus: "+AirplaneStatus+"\n"); sb.append("dataRoamStatus: "+dataRoamStatus+"\n"); txt.setText(sb.toString()); } }; }