android中getSystemService详解
- 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();
android中getSystemService详解的更多相关文章
- Android中Context详解 ---- 你所不知道的Context(转)
Android中Context详解 ---- 你所不知道的Context(转) 本文出处 :http://b ...
- Android中Context详解 ---- 你所不知道的Context
转自:http://blog.csdn.net/qinjuning/article/details/7310620Android中Context详解 ---- 你所不知道的Context 大家好, ...
- Android中 ListView 详解(二)
本文版权归 csdn noTice501 所有,转载请详细标明原作者及出处,以示尊重! 作者:noTice501 原文:http://blog.csdn.net/notice520/article/d ...
- Android中Handle详解
上图为本人总结的Handler,网上发现一片总结很好的博客就copy过来:作为参考 Handler有何作用?如何使用? 一 .Handler作用和概念 包含线程队列和消息队列,实现异步的消息处理机制, ...
- Android中Context详解
大家好, 今天给大家介绍下我们在应用开发中最熟悉而陌生的朋友-----Context类 ,说它熟悉,是应为我们在开发中时刻的在与它打交道,例如:Service.BroadcastReceiver.A ...
- 转:Android中Context详解 ---- 你所不知道的Context
转:http://blog.csdn.net/qinjuning/article/details/7310620 转:http://blog.csdn.net/lmj623565791/article ...
- android中LayoutInflater详解与使用
android的LayoutInflater用来得到一个布局文件,也就是xxx.xml,而我们常用的findviewbyid是用来取得布局文件里的控件或都布局.inflater即为填充的意思,也就是说 ...
- android中Actionbar详解
1.什么是Action BarAction Bar被认为是新版Android系统中最重要的交互元素,在程序运行中一直置于顶部,主要起到的作用在于:1)突出显示一些重要操作(如“最新”.“搜索”等)2) ...
- Android中IntentService详解
简单说,IntentService是继承于Service并处理异步请求的一个类,在IntentService内有一个工作线程来处理耗时操作,启动IntentService的方式和启动传统Service ...
随机推荐
- Mac下运行ASP.NET Core应用程序
Mac下运行ASP.NET Core应用程序 在Mac下运行ASP.NET Core应用程序 通过参照.NET Core相关官方文档,在我的Mac电脑上用Visual Studio Code创建了我的 ...
- 打造自己的程序员品牌(摘自Infoq)
John Sonmez是Simple Programmer的创始人.作者与程序员,关注于如何让复杂的事情变得简单.他是一位专业的软件开发者.架构师与讲师,感兴趣的领域包括测试驱动开发.如何编写整洁的代 ...
- asp.net 中给gridview添加自动序号
第一种方式,直接在Aspx页面GridView模板列中.这种的缺点是到第二页分页时又重新开始了. 代码如下: <asp:TemplateField HeaderText="序号&quo ...
- angular入门系列教程2
主题: 本篇主要介绍下angular里的一些概念,并且在咱们的小应用上加上点料.. 概念(大概了解即可,代码中遇到的会有详细注释): 模板:动态模板,是动态的,直接去处理DOM的,而不是通过处理字符串 ...
- BZOJ 4031: [HEOI2015]小Z的房间 Matrix-Tree定理
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=4031 题解: Matrix-tree定理解决生成树计数问题,其中用到高斯消元法求上三角矩 ...
- Exception in thread "http-bio-8081-exec-3" java.lang.OutOfMemoryError: PermGen space
前言: 在http://www.cnblogs.com/wql025/p/4865673.html一文中我曾描述这种异常也提供了解决方式,但效果不太理想,现在用本文的方式,效果显著. 目前此项目只能登 ...
- 如何将jsp中<input>设为只读
将一个input变为只读,可以使用 readonly 属性 和 disabled 属性. 用disabled 属性时,文字显示为灰色. 下面的两种方法都是可以的: <input id =&q ...
- 【Android自学之旅】 Android开发环境的搭建
[Android自学之旅] Android开发环境的搭建 搭建参考教程: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-do ...
- mysql导出多个表数据为excel方法,substring函数查询
//查询sys_username以S.00655开头的用户 ),sys_password FROM `tbl_sa_syslogin` where sys_username like 'S.%'; / ...
- android C/C++ source files 全局宏定义 .
\system\core\include\arch\linux-arm AndroidConfig.h * ============================================== ...