记录下这个getSystemService 的使用感觉这个API的用处挺大,很多东西都要用到它。
对于API的查询还不是特别会用,顺便借这个机会学习一下
getSystemService是在Context这个类下的方法,进入Api查询界面搜索Context,然后找到 向下查找就找到了getSystemService这个方法
以下是getSystemService的两个方法:
public final T getSystemService (Class<T> serviceClass)
Return the handle to a system-level service by class.
public abstract Object getSystemService (String name)
Return the handle to a system-level service by name.
一般我们用的是第二个方法,写法有两种一个是用的Context里定义的字符串常量,当然意思是一样的,由于返回的对象是Object所以要对放回的值进行转型。
WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
WifiManager wifiManager = (WifiManager)getSystemService("wifi");
例子二:
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
WindowManager windowManager = (WindowManager) getSystemService("window");
查询API上归纳了所有可获取的类如下:
Currently available classes are:
WindowManager,WINDOW_SERVICE ("window") :窗口管理器
LayoutInflater, LAYOUT_INFLATER_SERVICE ("layout_inflater"):布局
ActivityManager, ACTIVITY_SERVICE ("activity")
PowerManager, POWER_SERVICE ("power"):电源管理
AlarmManager, ALARM_SERVICE ("alarm"):闹钟管理
NotificationManager,NOTIFICATION_SERVICE ("notification"):通知栏管理
KeyguardManager, KEYGUARD_SERVICE ("keyguard")
LocationManager, LOCATION_SERVICE ("location"):位置管理
SearchManager, SEARCH_SERVICE ("search")
Vibrator, VIBRATOR_SERVICE ("vibrator") 手机震动
ConnectivityManager, CONNECTIVITY_SERVICE ("connection")
WifiManager, WIFI_SERVICE ("wifi"):wifi管理
AudioManager, WIFI_P2P_SERVICE ("wifip2p")
MediaRouter,Context.MEDIA_ROUTER_SERVICE这三个没有名称的方法
TelephonyManager, Context.TELEPHONY_SERVICE
SubscriptionManager, 这个比较特殊You do not instantiate this class directly; instead, you retrieve a reference to an instance through from(Context).
应该这么写吧:SubscriptionManager ubscriptionManager = SubscriptionManager.from(this);
InputMethodManager, INPUT_METHOD_SERVICE ("input_method")
UiModeManager, UI_MODE_SERVICE ("uimode")
DownloadManager, DOWNLOAD_SERVICE ("download")
BatteryManager, BATTERY_SERVICE ("batterymanager"):电池管理
JobScheduler,JOB_SCHEDULER_SERVICE ("taskmanager")
NetworkStatsManager.NETWORK_STATS_SERVICE ("netstats")
挺多的好多基本不认识,所以学会查看API是最基本的东西,这样才能方便学习。
这个个写个总结好像有点没完没了了。
贴上网上大神的总结吧
窗口管理
这个大家应用最多的应该都是用来获取手机屏幕的大小吧
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
int h = windowManager.getDefaultDisplay().getHeight();
int h = windowManager.getDefaultDisplay().getWidth();
用来获取布局文件的view
看介绍这个好像用到的概率比较小
http://www.cnblogs.com/top5/archive/2012/05/04/2482328.html
获取系统内存信息以及进程信息
http://www.2cto.com/kf/201111/111395.html
电源管理
http://blog.csdn.net/xieqibao/article/details/6562256
主要闹钟吧
http://blog.csdn.net/wangxingwu_314/article/details/8060312
这个通知栏的应该会用的比较多,基本的app都要用到吧
http://www.cnblogs.com/stay/articles/1898963.html
屏幕保护
http://blog.csdn.net/eyu8874521/article/details/8477724
定位服务
http://blog.csdn.net/liuhe688/article/details/6573459
利用此服务可以实现对系统中的应用、联系人、SMS等进行搜索
http://willsunforjava.iteye.com/blog/1674817
手机震动管理
http://www.android-study.com/jichuzhishi/414.html
网络连接,这个应该用的比较多吧,那个app不需要网络,需要就要对网络状态进行判断
http://blog.csdn.net/chenzheng_java/article/details/6387116/
对wifi的信息进行获取,判断处理
http://blog.csdn.net/hknock/article/details/7871866
手机音频文件的管理操作
http://blog.csdn.net/x605940745/article/details/16940097
好像比较复杂的样子
http://blog.csdn.net/lilian0118/article/details/22940943
用于管理手机通话状态,获取电话信息(设备信息、sim卡信息以及网络信息),
http://www.2cto.com/kf/201410/347844.html
http://blog.163.com/machao_163job/blog/static/2087753220121020101316838/
软键盘的输入控制
http://www.cnblogs.com/weixing/p/3300908.html
设置夜间模式和行车模式
http://blog.sina.com.cn/s/blog_8417aea80100v056.html
下载管理
http://blog.csdn.net/sir_zeng/article/details/8983430
这个东西可以让系统批处理一些不重要的APP 请求
http://blog.csdn.net/cuiran/article/details/42805057
这个网上找不到说明文章,说明大家应该都没有吧
Provides access to network usage history and statistics API说明:提供网络使用的历史记录和统计
这个方法都是query的查询方法,说明都是提供写网络使用的详细和统计的信息
总结完毕了,只能说大概了解了一遍基本功能。以后查找的时候能有些印象
本文详细介绍了Android中getSystemService方法的使用,包括其两种方法形式及如何通过该方法获取各种系统服务,如WiFiManager、WindowManager等,并提供了具体示例。
2595

被折叠的 条评论
为什么被折叠?



