zoukankan      html  css  js  c++  java
  • android获取系统wifi状态等

    WIFI

      获取WIFI状态

        WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);

        if(wifiManager != null){

          int wifiState = wifiManager.getWifiState();

        }

      附:Wifi状态有以下几种:(括号内为所对应的的int值)

      1. wifiManager.WIFI_STATE_DISABLED (1)

      2. wifiManager..WIFI_STATE_ENABLED (3)

      3. wifiManager..WIFI_STATE_DISABLING (0)

      4 wifiManager..WIFI_STATE_ENABLING  (2)

       设置wifi状态

        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

        if(wifiManager == null){

          return;

        }

        int wifiApState = wifiManager.getWifiApState();  //获取wifi AP状态

        if((boolean值 && wifiApState == wifiManager.WIFI_AP_STATE_ENABLING || wifiApState == wifiManager.WIFI_AP_STATE_ENABLED){

          wifiManager.setWifiApEnabled(null,false);

        }

        wifiManager.setWifiEnabled(boolean值);

        俩处boolean值应相同

    Bluetooth

    蓝牙有待后续补充

     

    GPS

      获取GPS状态

        ContentResolver resolver = context.ContextResolver();

        Boolean on = Settings.Secure.isLocationProviderEnabled(resolver, LocationManager.GPS_PROVIDER);

        true为开启状态

      设置GPS状态

        Settings..Secure.setLocationProviderEnabled(resolver,LocationManager.GPS_PROVIDER,boolean值);

        true为开启状态

    SYNC(同步)

      获取当前系统同步状态

        ContentResolver resolver = context.ContextResolver();

        Boolean on = resolver.getMasterSyncAutomatically();

        ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

         设置同步

        ContentResolver.setMasterSyncAutomatically(boolean值);

     

    AirplaneMode(飞行模式)

      获取系统当前飞行模式状态

        ContentResolver resolver = context.ContextResolver();

        boolean on = Settings.System.getInt(context.getContextResolver(),Settings.System.AIRPLANE_MODE_ON,0) == 1 ? true : false;

      设置飞行模式:

        Settings.System.putInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON,boolean值 ? 1 : 0);

        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);

        intent.putExtra("state",boolean值);

        context.sendBroadcast(intent);

      俩个boolean值应该一致;

     

     

    自动旋转屏幕

      获取系统当前自动旋屏设置

        ContentResolver resolver = context.ContextResolver();

        boolean on = Settings.System.getInt(context.getContResolver(),Settings.System.ACCELEROMETER_ROTATION) ==1 ? true : false;

      设置自动旋屏

        ContentResolver resolver = context.ContextResolver();

        Uri uri = Settings.System.getUriFor("accelerometer_rotation");

        Settings.System.putInt(resolver,"accelerometer_rotation",boolean值 ? 1 :0);

        resolver.notifyChange(uri,null);

     

    静音模式

      获取静音模式

      public int getMuteMode(Context context){

        AudioManager audioManager = (AudioManager)context.getSystmService(Context.AUDIO_SERVICE);

        if(audioManager.getRingerMode == AudioManager.RINGER_MODE_SILENT){   //静音

          return 0;

        }else if(audioManager.getRingerMode == AudioManager.RINGER_MODE_VIBRATE){//振动

          return 1;

        } elsse {

          retrn 2;

        }

      }

      设置静音模式

      public void setMute(Context context){

         AudioManager audioManager = (AudioManager)context.getSystmService(Context.AUDIO_SERVICE);

        switch(getMuteMode(context){

          case 0:

            audioManager.stRingerMode(AudioManager.RINGER_MODE_VIBRATE); //振动模式

            break;

          case 1:

            audioManager.stRingerMode(AudioManager.RINGER_MODE_NORMAL); //正常模式

            break;

          case 2:

            audioManager.stRingerMode(AudioManager.RINGER_MODE_SILENT); //静音模式

            break;

          default:

            audioManager.stRingerMode(AudioManager.RINGER_MODE_NORMAL); //正常模式

        }

      }

     

     锁屏

      PowerManager pm = (PowerManager)context.getSystemService(context.POWER_SERVICE);

      pm.goToSleep(SystemClock.uptimeMillis());

  • 相关阅读:
    多线程
    Flume和 Sqoop
    Struts2部分
    hibernate学习笔记(一)
    idea创建普通的java小项目教程
    IntelliJ Idea 常用快捷键列表
    idea创建springMVC框架和配置小文件
    对于Git的总结
    关于jvm运行时时区的总结
    事务的总结笔记(详解很仔细),mysql事务隔离级别演示,,,
  • 原文地址:https://www.cnblogs.com/aaa2832/p/3594751.html
Copyright © 2011-2022 走看看