Example usage for android.app AlarmManager setTimeZone

List of usage examples for android.app AlarmManager setTimeZone

Introduction

In this page you can find the example usage for android.app AlarmManager setTimeZone.

Prototype

public void setTimeZone(String timeZone) 

Source Link

Document

Sets the system's persistent default time zone.

Usage

From source file:com.android.managedprovisioning.DeviceOwnerProvisioningService.java

private void setTimeAndTimezone(String timeZone, long localTime) {
    try {/*www. ja v  a  2 s  .  c  o  m*/
        final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        if (timeZone != null) {
            if (DEBUG)
                ProvisionLogger.logd("Setting time zone to " + timeZone);
            am.setTimeZone(timeZone);
        }
        if (localTime > 0) {
            if (DEBUG)
                ProvisionLogger.logd("Setting time to " + localTime);
            am.setTime(localTime);
        }
    } catch (Exception e) {
        ProvisionLogger.loge("Alarm manager failed to set the system time/timezone.");
        // Do not stop provisioning process, but ignore this error.
    }
}

From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java

public String SetTimeZone(String sTimeZone) {
    String sRet = "Unable to set timezone to " + sTimeZone;
    TimeZone tz = null;// w ww . ja  va 2 s.c  o  m
    AlarmManager amgr = null;

    if ((sTimeZone.length() > 0) && (sTimeZone.startsWith("GMT"))) {
        amgr = (AlarmManager) contextWrapper.getSystemService(Context.ALARM_SERVICE);
        if (amgr != null)
            amgr.setTimeZone(sTimeZone);
    } else {
        String[] zoneNames = TimeZone.getAvailableIDs();
        int nNumMatches = zoneNames.length;
        int lcv = 0;

        for (lcv = 0; lcv < nNumMatches; lcv++) {
            if (zoneNames[lcv].equalsIgnoreCase(sTimeZone))
                break;
        }

        if (lcv < nNumMatches) {
            amgr = (AlarmManager) contextWrapper.getSystemService(Context.ALARM_SERVICE);
            if (amgr != null)
                amgr.setTimeZone(zoneNames[lcv]);
        }
    }

    if (amgr != null) {
        tz = TimeZone.getDefault();
        Date now = new Date();
        sRet = tz.getDisplayName(tz.inDaylightTime(now), TimeZone.LONG);
    }

    return (sRet);
}