android Setting中幾個設置項的設置,(USB StayAwake Locations):
直接貼代碼:
public void setUSBDebugger(){ int isUSBDebugging = -1; try { isUSBDebugging = Settings.Secure.getInt(getContentResolver(), Settings.Secure.ADB_ENABLED); if(isUSBDebugging == 0){ Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 1); } } catch (SettingNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void setStayAwake(){ int isStayAwake = -1; try { isStayAwake = Settings.System.getInt(getContentResolver(), Settings.System.STAY_ON_WHILE_PLUGGED_IN); if(isStayAwake == 0){ Settings.System.putInt(getContentResolver(), Settings.System.STAY_ON_WHILE_PLUGGED_IN, 3); } } catch (SettingNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void setLocations(){ int isLocations = -1; try { isLocations = Settings.Secure.getInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION); if(isLocations == 0){ Settings.Secure.putInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION, 1); } } catch (SettingNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }