[androdi基础知识] 之十六: ((TelephonyManager)paramContext.getSystemService("phone")).getDeviceId();语句的理解
2015-05-08 16:52
351 查看
前提:paramContext是一个preferenceActivity,它的getSystemService("phone")).getDeviceId()用于干什么呢?
参考:http://blog.sina.com.cn/s/blog_7cb2c5d50101c26t.html
这个里面关键点在于 getSystemService函数,是Android很重要的一个API,它是Activity的一个方法.
根据传入的NAME来取得对应的Object,然后转换成相应的服务对象。以下介绍系统相应的服务。
传入的Name | 返回的对象 | 说明
WINDOW_SERVICE WindowManager 管理打开的窗口程序
LAYOUT_INFLATER_SERVICE LayoutInflater 取得xml里定义的view
ACTIVITY_SERVICE ActivityManager 管理应用程序的系统状态
POWER_SERVICE PowerManger 电源的服务
ALARM_SERVICE AlarmManager 闹钟的服务
NOTIFICATION_SERVICE NotificationManager 状态栏的服务
KEYGUARD_SERVICE KeyguardManager 键盘锁的服务
LOCATION_SERVICE LocationManager 位置的服务,如GPS
SEARCH_SERVICE SearchManager 搜索的服务
VEBRATOR_SERVICE Vebrator 手机震动的服务
CONNECTIVITY_SERVICE Connectivity 网络连接的服务
WIFI_SERVICE WifiManager Wi-Fi服务
TELEPHONY_SERVICE TeleponyManager 电话服务
Currently available names are:
WINDOW_SERVICE ("window")
The top-level window manager in which you can place custom windows. The returned object is a WindowManager.
LAYOUT_INFLATER_SERVICE ("layout_inflater")
A LayoutInflater for inflating layout resources in this context.
ACTIVITY_SERVICE ("activity")
A ActivityManager for interacting with the global activity state of the system.
POWER_SERVICE ("power")
A PowerManager for controlling power management.
ALARM_SERVICE ("alarm")
A AlarmManager for receiving intents at the time of your choosing.
NOTIFICATION_SERVICE ("notification")
A NotificationManager for informing the user of background events.
KEYGUARD_SERVICE ("keyguard")
A KeyguardManager for controlling keyguard.
LOCATION_SERVICE ("location")
A LocationManager for controlling location (e.g., GPS) updates.
SEARCH_SERVICE ("search")
A SearchManager for handling search.
VIBRATOR_SERVICE ("vibrator")
A Vibrator for interacting with the vibrator hardware.
CONNECTIVITY_SERVICE ("connection")
A ConnectivityManager for handling management of network connections.
WIFI_SERVICE ("wifi")
A WifiManager for management of Wi-Fi connectivity.
INPUT_METHOD_SERVICE ("input_method")
An InputMethodManager for management of input methods.
UI_MODE_SERVICE ("uimode")
An UiModeManager for controlling UI modes.
DOWNLOAD_SERVICE ("download")
A DownloadManager for requesting HTTP downloads
Note: System services obtained via this API may be closely associated with the Context in which they are obtained from. In general, do not share the service objects between various different contexts (Activities, Applications, Services, Providers, etc.)
一个例子:
在android 获取手机信息的时候用到这样一段代码:
public class BasicInfo {
public String getPhoneNumber()
{
//
获取手机号 MSISDN,很可能为空
TelephonyManager
tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
StringBuffer
inf = new StringBuffer();
switch(tm.getSimState()){
//getSimState()取得sim的状态 有下面6中状态
case
TelephonyManager.SIM_STATE_ABSENT :inf.append("无卡");return inf.toString();
case
TelephonyManager.SIM_STATE_UNKNOWN :inf.append("未知状态");return inf.toString();
case
TelephonyManager.SIM_STATE_NETWORK_LOCKED :inf.append("需要NetworkPIN解锁");return inf.toString();
case
TelephonyManager.SIM_STATE_PIN_REQUIRED :inf.append("需要PIN解锁");return inf.toString();
case
TelephonyManager.SIM_STATE_PUK_REQUIRED :inf.append("需要PUK解锁");return inf.toString();
case
TelephonyManager.SIM_STATE_READY :break;
}
String phoneNumber = tm.getLine1Number();
return phoneNumber;
}
参考:http://blog.sina.com.cn/s/blog_7cb2c5d50101c26t.html
这个里面关键点在于 getSystemService函数,是Android很重要的一个API,它是Activity的一个方法.
根据传入的NAME来取得对应的Object,然后转换成相应的服务对象。以下介绍系统相应的服务。
传入的Name | 返回的对象 | 说明
WINDOW_SERVICE WindowManager 管理打开的窗口程序
LAYOUT_INFLATER_SERVICE LayoutInflater 取得xml里定义的view
ACTIVITY_SERVICE ActivityManager 管理应用程序的系统状态
POWER_SERVICE PowerManger 电源的服务
ALARM_SERVICE AlarmManager 闹钟的服务
NOTIFICATION_SERVICE NotificationManager 状态栏的服务
KEYGUARD_SERVICE KeyguardManager 键盘锁的服务
LOCATION_SERVICE LocationManager 位置的服务,如GPS
SEARCH_SERVICE SearchManager 搜索的服务
VEBRATOR_SERVICE Vebrator 手机震动的服务
CONNECTIVITY_SERVICE Connectivity 网络连接的服务
WIFI_SERVICE WifiManager Wi-Fi服务
TELEPHONY_SERVICE TeleponyManager 电话服务
Currently available names are:
WINDOW_SERVICE ("window")
The top-level window manager in which you can place custom windows. The returned object is a WindowManager.
LAYOUT_INFLATER_SERVICE ("layout_inflater")
A LayoutInflater for inflating layout resources in this context.
ACTIVITY_SERVICE ("activity")
A ActivityManager for interacting with the global activity state of the system.
POWER_SERVICE ("power")
A PowerManager for controlling power management.
ALARM_SERVICE ("alarm")
A AlarmManager for receiving intents at the time of your choosing.
NOTIFICATION_SERVICE ("notification")
A NotificationManager for informing the user of background events.
KEYGUARD_SERVICE ("keyguard")
A KeyguardManager for controlling keyguard.
LOCATION_SERVICE ("location")
A LocationManager for controlling location (e.g., GPS) updates.
SEARCH_SERVICE ("search")
A SearchManager for handling search.
VIBRATOR_SERVICE ("vibrator")
A Vibrator for interacting with the vibrator hardware.
CONNECTIVITY_SERVICE ("connection")
A ConnectivityManager for handling management of network connections.
WIFI_SERVICE ("wifi")
A WifiManager for management of Wi-Fi connectivity.
INPUT_METHOD_SERVICE ("input_method")
An InputMethodManager for management of input methods.
UI_MODE_SERVICE ("uimode")
An UiModeManager for controlling UI modes.
DOWNLOAD_SERVICE ("download")
A DownloadManager for requesting HTTP downloads
Note: System services obtained via this API may be closely associated with the Context in which they are obtained from. In general, do not share the service objects between various different contexts (Activities, Applications, Services, Providers, etc.)
一个例子:
在android 获取手机信息的时候用到这样一段代码:
public class BasicInfo {
public String getPhoneNumber()
{
//
获取手机号 MSISDN,很可能为空
TelephonyManager
tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
StringBuffer
inf = new StringBuffer();
switch(tm.getSimState()){
//getSimState()取得sim的状态 有下面6中状态
case
TelephonyManager.SIM_STATE_ABSENT :inf.append("无卡");return inf.toString();
case
TelephonyManager.SIM_STATE_UNKNOWN :inf.append("未知状态");return inf.toString();
case
TelephonyManager.SIM_STATE_NETWORK_LOCKED :inf.append("需要NetworkPIN解锁");return inf.toString();
case
TelephonyManager.SIM_STATE_PIN_REQUIRED :inf.append("需要PIN解锁");return inf.toString();
case
TelephonyManager.SIM_STATE_PUK_REQUIRED :inf.append("需要PUK解锁");return inf.toString();
case
TelephonyManager.SIM_STATE_READY :break;
}
String phoneNumber = tm.getLine1Number();
return phoneNumber;
}
相关文章推荐
- android7.0关于TelephonyManager.getDeviceId()返回null的问题
- [android基础知识] 之四:TelephonyManager service的使用实例
- ServiceManager.getService和Context.getSystemService
- system_service进程里 调用SystemManager.getService("activity") 直接返回ams的引用?
- android中getSystemService通过系统提供的Manager接口来访问及设置服务数据
- Android Context getSystemService分析
- Can't User UserProfileManager.GetUserProfile Get User Userprofile In Web Service,Error:System.ArgumentNullException: Value Cannot Be Null.(不能在Webservice中使用UserProfileManager的GetUserProfile得到用户配置,报错:System.ArgumentNullException: 值不能为空。)
- Mysql EF 触发器生成主键id 存储区更新、插入或删除语句影响到了意外的行数(0)。实体在加载后可能被修改或删除。刷新 ObjectStateManager 项 ;System.Data.Entity.Infrastructure.DbUpdateConcurrencyException
- SQL Server 索引基础知识(5)----理解newid()和newsequentialid()
- context.getSystemService(context.LAYOUT_INFLATER_SERVICE)调用时报NullPointerException
- Android getContext().getSystemService()
- context.getSystemService(context.LAYOUT_INFLATER_SERVICE)调用时报NullPointerException
- SQL Server 索引基础知识(5)----理解newid()和newsequentialid()(转自蝈蝈俊.net)
- 【Android】java.lang.SecurityException: getDeviceId: Neither user 10065 nor current process has android.permission.READ_PHONE_STATE
- SQL Server 索引基础知识(5)----理解newid()和newsequentialid()
- Android基础知识_Context的理解及使用
- context.getSystemService的简单说明
- SQL Server 索引基础知识(5)----理解newid()和newsequentialid()
- javascript typeof id==='string'?document.getElementById(id):id解释[原创]_基础知识_脚本之家
- Context.getSystemService