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 电话服务
分享到:
相关推荐
这个文档对android中的getSystemService有详细的讲解
Android的getSystemService函数学习总结
本文实例分析了Android getSystemService用法。分享给大家供大家参考,具体如下: 1. 说明 android的后台运行在很多service,它们在系统启动时被SystemServer开启,支持系统的正常工作,比如MountService监听是否有...
通过 Context.getSystemService().方法获取PowerManager实例。 然后通过PowerManager的newWakeLock ((int flags, String tag)来生成WakeLock实例。int Flags指示要获取哪种WakeLock,不同的Lock对cpu 、屏幕、键盘灯...
Android长按复制文本,长按粘贴文本。Android长按复制文本,长按粘贴文本。
ConnectivityManager cm = (ConnectivityManager) context.getSystemService( 3. Context.CONNECTIVITY_SERVICE); 4. NetworkInfo info = cm.getActiveNetworkInfo(); 5. return (info != null && info....
Beginning iOS 6 Development Exploring the iOS SDK SourceCode
在Android里,程序内存被分为2部分:native和dalvik,dalvik就是我们普通的Java使用内存,分析堆栈的时候使用的内存。...ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVIC
TelephonyManager tm=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);//创建TelephonyManager对象 tm.listen(mPSL, PhoneStateListener.LISTEN_CALL_STATE);//添加监听器
TelephonyManager类的对象可以通过Context.getSystemService(Context.TELEPHONY_SERVICE)方法来获得,需要注意的是有些通讯信息的获取对应用程序的权限有一定的限制,在开发的时候需要为其添加相应的权限。
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); 3.使用inflate(int resource, ViewGroup root)方法生成新的View 4.调用当前页面中某个容器的addView,将新创建的...
ActivityManager mActivityManager = (ActivityManager) myContext.getSystemService(Context.ACTIVITY_SERVICE); Method method = Class.forName("android.app.ActivityManager").getMethod("forceStopPackage", ...
代码扒自Facebook的开源项目React Native 摇晃手机打开开发者选项的代码 ...使用方法: ShakeDetector shakeDetector = new ShakeDetector... shakeDetector.start((SensorManager) getSystemService(SENSOR_SERVICE));
final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final Class conmanClass = Class.forName(conman.getClass().getName()); final Field ...
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); //定义接近区域的大致经度、纬度 double longitude = 113.39; double latitude = 23.13; //定义接近区域的半径(5...
.getSystemService(Context.ALARM_SERVICE); // Action指向我们的BoxinReceiver Intent intent = new Intent(this, BoxinReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(MainActivity....
.getSystemService(Context.LOCATION_SERVICE); if (alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) { Toast.makeText(this, "GPS模块正常", Toast.LENGTH_SHORT).show(); ...
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); tv = (TextView) findViewById(R.id.tv); localPowerManager = (PowerManager) getSystemService(POWER_SERVICE); // 获取PowerManager....
mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams() layoutParams.type = WindowManager....