【问题标题】:System settings?系统设置?
【发布时间】:2013-12-08 07:51:48
【问题描述】:

我需要编写一个应用程序来打开设备,这是一个 htc 平板电脑,以控制设备的 wifi 开和关设置以及 gps 开和关设置。应用程序可以控制这些吗?如果可以,我以前从未使用过系统设置吗?任何教育 pdf、网站或 youtube 视频也会很棒。非常感谢。

【问题讨论】:

    标签: android settings system


    【解决方案1】:

    使用以下权限

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
    

    您可以使用

    进行检查

    boolean wifiEnabled = wifiManager.isWifiEnabled()

     wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); 
     wifiManager.setWifiEnabled(true);
     wifiManager.setWifiEnabled(false);
    

    GPS

    使用这个

    private void turnGPSOn(){
    String provider = Settings.Secure.getString(getContentResolver(),    
    Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
    
    if(!provider.contains("gps")){ //if gps is disabled
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); 
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3")); 
        sendBroadcast(poke);
      }
    }
    
    private void turnGPSOff(){
    String provider = Settings.Secure.getString(getContentResolver(),      
    Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
    
    if(provider.contains("gps")){ //if gps is enabled
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3")); 
        sendBroadcast(poke);
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-20
      • 1970-01-01
      • 1970-01-01
      • 2017-05-17
      • 2019-08-01
      • 2014-02-04
      相关资源
      最近更新 更多