Android——getSystemService
android的后台运行在很多service,它们在系统启动时被SystemServer开启,支持系统的正常工作,比如MountService监 听是否有SD卡安装及移除,ClipboardService提供剪切板功能,PackageManagerService提供软件包的安装移除及查看等 等,应用程序可以通过系统提供的Manager接口来访问这些Service提供的数据。
- 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
电话服务
- 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
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;
}
在另外一个activity类里面调用的时候 总是出现进程关闭 无法获取手机信息。后来发现
|
|
于是:
1. 给BasicInfo
添加一个带参数Context的构造函数:
public BasicInfo (Context context)
{
this.context =
context;
}
2. getPhoneNumber()函数里面改成:
context.getSystemService(Context.TELEPHONY_SERVIC);
3. 在调用类里面 BasicInfo bi = new
BasicInfo(this);
bi.getPhoneNumber();
引自:http://blog.sina.com.cn/s/blog_7cb2c5d50101c26t.html
Android——getSystemService的更多相关文章
- Android -- getSystemService
Android的后台运行在很多service,它们在系统启动时被SystemServer开启,支持系统的正常工作,比如MountService监听是否有SD卡安装及移除,ClipboardServic ...
- Android操作系统服务(Context.getSystemService() )
getSystemService是Android很重要的一个API,它是Activity的一个方法,根据传入的NAME来取得对应的Object,然后转换成相应的服务对象.下面介绍系统相应的服务: 传入 ...
- android中getSystemService详解
android的后台运行在很多service,它们在系统启动时被SystemServer开启,支持系统的正常工作,比如MountService监 听是否有SD卡安装及移除,ClipboardS ...
- Android:getContext().getSystemService()
一.介绍 getSystemService是Android很重要的一个API,它是Activity的一个方法,根据传入的NAME来取得对应的Object,然后转换成相应的服务对象 二.语法 Windo ...
- Android Service GetSystemService
http://blog.sina.com.cn/s/blog_71d1e4fc0100o8qr.html http://blog.csdn.net/bianhaohui/article/details ...
- Android之getSystemService
getSystemService是Android很重要的一个API,它是Activity的一个方法,根据传入的NAME来取得对应的Object,然后转换成相应的服务对象.以下介绍系统相应的服务. 传入 ...
- android window(二)从getSystemService到WindowManagerGlobal
在Activity调用getSystemService(WINDOW_SERVICE) 调用的是父类ContextThemeWrapper package android.view; public c ...
- 【Android】 context.getSystemService()浅析
同事在进行code review的时候问到我context中的getSystemService方法在哪实现的,他看到了一个ClipBoardManager来进行剪切板存储数据的工具方法中用到了cont ...
- Android指纹解锁
Android6.0及以上系统支持指纹识别解锁功能:项目中用到,特此抽离出来,备忘. 功能是这样的:在用户将app切换到后台运行(超过一定的时长,比方说30秒),再进入程序中的时候就会弹出指纹识别的界 ...
随机推荐
- objective-c 随便记记
1.tableview滚动到某一位置 [tableViewShow setContentOffset:CGPointMake(0, 0) animated:YES]; //解决tableView分割线 ...
- 激活Maven profile的几种方式
首先简单介绍下 Maven 的 profile 是什么.对于人来说,profile 是指人的肖像,轮廓,比如论坛里每个人注册了帐号后,可以设置自己的 profile,放上照片,介绍等等.对于 Mave ...
- Linux文件系统Ext2,Ext3,Ext4性能大比拼
Linux kernel 自 2.6.28 开始正式支持新的文件系统 Ext4. Ext4 是 Ext3 的改进版,修改了 Ext3 中部分重要的数据结构,而不仅仅像 Ext3 对 Ext2 那样,只 ...
- 把docker当做绿色打包工具
如题,我只是把docker当成绿色版的各种环境的集成打包工具了 用到了docker的--net=host模式,这个暂时在mac下是有问题的,linux下正常使用,具体docker的网络模式参考这里,此 ...
- httpd安装
1.软件准备 http://apache.fayea.com/apache-mirror//apr/apr-1.5.1.tar.gz http://apache.fayea.com/apache-mi ...
- Hadoop学习3--安装ssh服务
题前语:为什么要安装这个东西呢? 是因为我们要在多台机器之间通信,这个服务就相当于支持这种通信的一个桥梁,打个比喻,相当于windows里,通过远程桌面连接到其他机器. 所以,安装这个服务,的目的是: ...
- 黄聪:优化清理WordPress数据库wp_options表(缩小autoload体积)
使得wp_options表变得庞大的重要原因:无用的RSS Feed Cache.如果你在wp_options表中发现了大量option_name包含“_transient”的数据,那就是它没跑了.先 ...
- iphone Dev 开发实例10:How To Add a Slide-out Sidebar Menu in Your Apps
Creating the Xcode Project With a basic idea about what we’ll build, let’s move on. You can create t ...
- 将网站部署到windows2003 iis6之后,出现asp.net程序页面无法访问情况
idc的技术说是没有装.net framework 2.0的缘故. 可是我已经装了4.0. 后来把一个伪静态的组件卸载了,就可以了.
- 让 SVN (TortoiseSVN)提交时忽略bin和obj目录
2013-06-23 更新 后来我使用属性来过滤,结果反而没有效果了,之后我再次尝试使用全局忽略样式设置:*/bin */obj */packages 结果又有效果了,奇怪了. ------- 由于我 ...