当前位置:天才代写 > tutorial > 安卓教程 > android获取系统wifi状态等

android获取系统wifi状态等

2021-02-16 15:04 星期二 所属: 安卓教程 浏览:391

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());

 

    关键字:

天才代写-代写联系方式