zoukankan      html  css  js  c++  java
  • 通过getSystemServices获取手机管理大全

    getSystemServiceAndroid很重要的一个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 = new
    05  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的Intent
    02  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    //获取屏幕管理器
    02    WindowManagermWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); 
    03    //获取宽度
    04    width = mWindowManager.getDefaultDisplay().getWidth();
    05    //获取高度
    06    height = mWindowManager.getDefaultDisplay().getHeight();  

    本文摘自明日科技出版的《Android 精彩编程200例》,转载请注明出处!!!

  • 相关阅读:
    陶瓷电容的结构、工艺、失效模式
    Vue.js最佳实践
    Vue 超快速学习
    CSS 小技巧
    HTML5 Canvas
    webkit下面的CSS设置滚动条
    Some untracked working tree files would be overwritten by checkout. Please move or remove them before you can checkout. View them
    JSCS: Please specify path to 'JSCS' package
    React中ref的使用方法
    React 60S倒计时
  • 原文地址:https://www.cnblogs.com/mrxy/p/7988162.html
Copyright © 2011-2022 走看看