Hi all.
Each time application starts, we set license. Each time created from JSON string license is expired. It's offline application. We need to set license without internet connection, without asking each time from portal. How to?
private void setupEsriLicense() { try { appSettings = getSharedPreferences(Global.SETTINGS_FILE, MODE_PRIVATE); boolean getFromPortal = true; if (appSettings != null && appSettings.contains(Global.LICENSE_TAG)) { String licJson = appSettings.getString(Global.LICENSE_TAG, null); LicenseInfo licenseInfo = new LicenseInfo(licJson); LicenseResult licenseResult = ArcGISRuntimeEnvironment.setLicense(licenseInfo); LicenseStatus licenseStatus = licenseResult.getLicenseStatus(); // licenseStatus is always EXPIRED if (licenseStatus == LicenseStatus.VALID) { getFromPortal = false; } } if (getFromPortal) { UserCredential credential = new UserCredential("username", "passwd"); final Portal portal = new Portal("https://companyname.maps.arcgis.com"); portal.setCredential(credential); portal.loadAsync(); portal.addDoneLoadingListener(new Runnable() { @Override public void run() { if (portal.getLoadStatus() == LoadStatus.LOADED) { LicenseInfo licenseInfo = portal.getPortalInfo().getLicenseInfo(); LicenseResult licenseResult = ArcGISRuntimeEnvironment.setLicense(licenseInfo); LicenseStatus licenseStatus = licenseResult.getLicenseStatus(); if (licenseStatus == LicenseStatus.VALID) { // always VALID SharedPreferences.Editor editor = appSettings.edit(); editor.putString(Global.LICENSE_TAG, licenseInfo.toJson()); editor.commit(); } //TODO: remove from release License runtimeLicense = ArcGISRuntimeEnvironment.getLicense(); Calendar cal = runtimeLicense.getExpiry(); // always +30 days LicenseStatus ls = runtimeLicense.getLicenseStatus(); // always VALID LicenseLevel ll = runtimeLicense.getLicenseLevel(); // always BASIC LicenseType lt = runtimeLicense.getLicenseType(); // always NAMED_USER } } }); } } catch (Exception ex) { Log.d(TAG, "setupEsriLicense", ex); } } Thanks for your ansewers. Ivan
Solved.
//LicenseInfo licenseInfo = new LicenseInfo(licJson); // EXPIRED LicenseInfo licenseInfo = LicenseInfo.fromJson(licJson); // VALID Miracle!