Example usage for android.app.admin DevicePolicyManager EXTRA_PROVISIONING_LOCAL_TIME

List of usage examples for android.app.admin DevicePolicyManager EXTRA_PROVISIONING_LOCAL_TIME

Introduction

In this page you can find the example usage for android.app.admin DevicePolicyManager EXTRA_PROVISIONING_LOCAL_TIME.

Prototype

String EXTRA_PROVISIONING_LOCAL_TIME

To view the source code for android.app.admin DevicePolicyManager EXTRA_PROVISIONING_LOCAL_TIME.

Click Source Link

Document

A Long extra holding the wall clock time (in milliseconds) to be set on the device's android.app.AlarmManager .

Usage

From source file:com.example.android.nfcprovisioning.NfcProvisioningFragment.java

@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    if (mProvisioningValues == null) {
        return null;
    }//from www  .j a v a  2s .  co  m
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    Properties properties = new Properties();
    // Store all the values into the Properties object
    for (Map.Entry<String, String> e : mProvisioningValues.entrySet()) {
        if (!TextUtils.isEmpty(e.getValue())) {
            String value;
            if (e.getKey().equals(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID)) {
                // Make sure to surround SSID with double quotes
                value = e.getValue();
                if (!value.startsWith("\"") || !value.endsWith("\"")) {
                    value = "\"" + value + "\"";
                }
            } else {
                value = e.getValue();
            }
            properties.put(e.getKey(), value);
        }
    }
    // Make sure to put local time in the properties. This is necessary on some devices to
    // reliably download the device owner APK from an HTTPS connection.
    if (!properties.contains(DevicePolicyManager.EXTRA_PROVISIONING_LOCAL_TIME)) {
        properties.put(DevicePolicyManager.EXTRA_PROVISIONING_LOCAL_TIME,
                String.valueOf(System.currentTimeMillis()));
    }
    try {
        properties.store(stream, getString(R.string.nfc_comment));
        NdefRecord record = NdefRecord.createMime(DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC,
                stream.toByteArray());
        return new NdefMessage(new NdefRecord[] { record });
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}