Android_服务于广播(2)

来源:互联网 发布:centos安装vim编辑器 编辑:程序博客网 时间:2024/06/06 01:47
1.获取手机SIM卡信息
    //获得服务
   tm.(TelephoneyManager)getSystemService(Context.TELEPHONY_SERVICE);
    //获得设备的编号
     StringdeviceId=tm.getDeviceId();
   //获得SIM的国别
     StringCountry=tm.getSimCountryIso();
    //获得SIM卡的序列号
    StringSIMSerial=tm.getSerialNumber();
    //获得SIM卡的状态
   StringSIMState=simState[tm.getSimState()];
    //获得网络运行商的名称
    StringnetworkOperatorName=tm.getNetworkOperatorName();
   //获得手机的制式
     StringphoneType=phoneTypes[tm.getPhoneType()];

2.获得系统软键盘
    //获得对象
  imm=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
  //第一次调用显示,再次调用则隐藏,如何反复
  imm.toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS);

3.开启行车模式,夜光模式
    //获得对象
   uiModeManager=(UiModeManager)getSystemService(Context.UI_MODE_SERVICE);
   //行车模式
  uiModeManager.enableCarMode(UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME);
   //夜间模式
 uiModeManager.setNightMode(UiModeManager.MODE_NIGHT_YES);

4.音量控制器
   audioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
   //得到当前的通话声音
   intcurrentCall=audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
   //得到当前的系统音量
   intcurrentSystem=audioManager.getStreamVolume(AudioManager.STREAM_MUSIC):
   //得到当前的提示音声音音量
    intcurrentTip=audioManager.getStreamVolum(AudioManager.STREAM_ALARM);
  //增加系统音量、参数1.声音类型,参数2.调整音量的方向,参数3.可选的标志位
   audioManager.adjustStramVolum(AudioManager.STREAM_SYSTEM,AudioManager.ADJUST_RAISE,AudioManager.Fx_FOCUS_NAVIGATION_UP);
   
5.手机电池补充
    //得到电池的电压
    intvoltage=intent.getIntExtra("voltage",0);
    //得到电池的温度
     inttemperature=intent.getIntExtra("temperature",0);
   //得到电池的类型
     Stringtexhnology=intent.getStringExtra("technology");

6.桌面空间方式
    //创建
   intent shortcut=newIntent(CREATE_SHORTCUT_ACTION);
    //得到包名
   Intent shortcutIntent=cx.getPackageManager().getLaunchIntentForPackage(cx.getPackageName());
   //设置快捷方式的单击指向
   shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shotcutIntent);
 

0 0