通过getSystemServices获取手机管理大全
来源:互联网 发布:手机淘宝无法安装 编辑:程序博客网 时间:2024/05/18 02:53
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
电话服务
示例1:图书《Android精彩编程200例》,实例006状态栏的服务例子:
获取通知管理器并创建通知对象。代码如下:
01 //获取通知管理器,用于发送通知02 Notif icationManager notif icationManager =03 (Notif icationManager) getSystemService(NOTIFICATION_SERVICE);04 Notif icationCompat.Builder notif ication = new05 Notif icationCompat.Builder(MainActivity.this); //创建一个Notif ication对象
设置通知的相关参数与通知的发送时间。代码如下:
01 notification.setAutoCancel(true);02 //设置显示在状态栏的通知提示信息03 notification.setTicker("Android课程第一季上线啦!");04 //设置通知的小图标05 notification.setSmallIcon(R.mipmap.ic_launcher);06 //设置下拉列表中的大图标07notification.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher));08 //设置通知内容的标题09 notification.setContentTitle("Android入门第一季!");10 //设置通知内容11 notification.setContentText("点击查看详情!");12 //设置发送时间13 notification.setWhen(System.currentTimeMillis());
设置从通知栏跳转至通知的详细内容界面,并进行通知的发送。代码如下:
01 //创建一个启动其他Activity的Intent02 Intent intent = new Intent(MainActivity.this,03 MessageActivity.class);04 PendingIntent pi = PendingIntent.getActivity(05 MainActivity.this, 0, intent, 0);06 //设置通知栏单击跳转07 notification.setContentIntent(pi);08 //发送通知09 notificationManager.notify(NOTIFYID, notification.build());
示例2:常用功能,获取屏幕高度宽度,代码如下:
01//获取屏幕管理器02WindowManagermWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); 03//获取宽度04width = mWindowManager.getDefaultDisplay().getWidth();05//获取高度06height = mWindowManager.getDefaultDisplay().getHeight();
本文摘自明日科技出版的《Android 精彩编程200例》,转载请注明出处!!!
- 通过getSystemServices获取手机管理大全
- 通过getSystemServices获取手机管理大全
- android获取手机信息大全
- android获取手机信息大全
- android获取手机信息大全
- Android获取手机信息大全
- android获取手机信息大全
- android获取手机信息大全
- android获取手机信息大全
- Android获取手机信息大全
- android获取手机信息大全
- android获取手机信息大全
- 通过adb获取手机信息
- android获取手机相关信息大全
- 通过读数据库来获取手机联系人
- 通过TelephonyManager获取本地手机信息
- 通过adb直接获取手机信息
- 通过代码实现获取手机CPU信息
- windows查看默认编码类型
- 关于Halcon基于特征点图像拼接的算子实现
- 设计模式的艺术之道--原型模式
- Android4.4高通平台中的应用路径及应用裁剪方法
- getComputedStyle 使用方法
- 通过getSystemServices获取手机管理大全
- iOS:UITableView实现飘带动画
- Maven的使用(Myeclipse)
- 通过递增快照备份 Azure 非托管 VM 磁盘
- Java集合总结之Collection整体框架
- Tomcat 架构分析(一) 体系结构
- onnx on OSX
- Median of Two Sorted Arrays
- Linux的内核相关问题