getSystemService的使用示例
来源:互联网 发布:java程序性能优化 编辑:程序博客网 时间:2024/05/22 07:54
1.设备管理器 系统服务
// 拿到一个设备管理器DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);// new一个新的组件出来,用来启动注册管理器的界面ComponentName componentName = new ComponentName(this,MyAdminReceiver.class);// 判断是否已经注册,没有就进行注册if (!devicePolicyManager.isAdminActive(componentName)){Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,componentName);startActivity(intent);}
2.窗口,来电显示 系统服务
windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);listener = new MyPhoneListener();telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
private class MyPhoneListener extends PhoneStateListener{@Overridepublic void onCallStateChanged(int state, String incomingNumber) {// TODO Auto-generated method stubsuper.onCallStateChanged(state, incomingNumber);switch (state) {case TelephonyManager.CALL_STATE_IDLE: //空闲状态if(tv != null){windowManager.removeView(tv); //移除显示归属的那个View}break;case TelephonyManager.CALL_STATE_OFFHOOK: //接通电话if(tv !=null){windowManager.removeView(tv); //移除显示归属的那个View}break;case TelephonyManager.CALL_STATE_RINGING: //响铃状态String address = NumberAddressService.getAddress(incomingNumber);showLocation(address);break;default:break;}}
3.通知栏的 系统服务
@SuppressWarnings("deprecation")private void showNotifycation(String number){//拿到Notifycation的管理者NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);//new 一个Notifycation出来@SuppressWarnings("deprecation")Notification notification = new Notification(R.drawable.notification,"发现响一声",System.currentTimeMillis());Context context = getApplicationContext();//设置成一点就消失notification.flags = Notification.FLAG_AUTO_CANCEL;Intent notificationIntent = new Intent(context,NumberSecurityActivity.class);notificationIntent.putExtra("number", number);PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,notificationIntent,0);notification.setLatestEventInfo(context, "响一声号码", number, pendingIntent);//激活NotificationnotificationManager.notify(0, notification);}
0 0
- getSystemService的使用示例
- LayoutInflater的使用 和getSystemService系统服务
- LayoutInflater的使用 和getSystemService系统服务
- LayoutInflater的使用 和getSystemService系统服务
- 几种getSystemService() 及其使用的时机
- getSystemService方法的调用
- getSystemService 的参数
- Android的 getSystemService
- getSystemService() 的API列表
- getSystemService方法的调用
- getSystemService的原理
- Android的getSystemService(String)
- Android getSystemService()的API
- getSystemService方法的调用
- GetSystemService的详解
- Android的getSystemService()
- getSystemService
- getSystemService
- C++与C#中this的作用
- NYOJ 1112 求次数 (map)
- CentOS 7 安装百度云linux版
- 升级Ubuntu 12.04的gcc,g++ 升级到4.7
- HDU 1695 GCD(容斥+组合)
- getSystemService的使用示例
- Oracle VM VirtualBox启动新建虚拟机弹错--不能为虚拟机xxxx电脑 打开一个新任务
- 程序员技术练级攻略
- 设计模式之策略模式
- iOS之UINavigationController的使用
- JSON 字符串 与 java 对象的转换
- 4-PSK、4-DPSK、8-QAM信号调制
- PHP基础知识(二)
- LEETCODE: Single Number II