/** * This is used to send the registration Id to MDM server so that the server can use it as a * reference to identify the device when sending messages to Google server. * * @throws AndroidAgentException */ public void sendRegistrationId() throws AndroidAgentException { DeviceInfo deviceInfo = new DeviceInfo(context); DeviceInfoPayload deviceInfoPayload = new DeviceInfoPayload(context); deviceInfoPayload.build(); String replyPayload = deviceInfoPayload.getDeviceInfoPayload(); String ipSaved = Preference.getString(context, Constants.IP); ServerConfig utils = new ServerConfig(); utils.setServerIP(ipSaved); String url = utils.getAPIServerURL() + Constants.DEVICE_ENDPOINT + deviceInfo.getDeviceId(); CommonUtils.callSecuredAPI( context, url, org.wso2.emm.agent.proxy.utils.Constants.HTTP_METHODS.PUT, replyPayload, RegistrationActivity.this, Constants.GCM_REGISTRATION_ID_SEND_CODE); }
private void registerDevice() { progressDialog = CommonDialogUtils.showPrgressDialog( RegistrationActivity.this, getResources().getString(R.string.dialog_enrolling), getResources().getString(R.string.dialog_please_wait), null); progressDialog.show(); String type = Preference.getString( context, context.getResources().getString(R.string.shared_pref_reg_type)); String username = Preference.getString(context, context.getResources().getString(R.string.username)); try { deviceInfoBuilder.build(type, username); } catch (AndroidAgentException e) { Log.e(TAG, "Error occurred while building the device info payload.", e); } // Check network connection availability before calling the API. if (CommonUtils.isNetworkAvailable(context)) { // Call device registration API. String ipSaved = Preference.getString(context.getApplicationContext(), Constants.IP); ServerConfig utils = new ServerConfig(); utils.setServerIP(ipSaved); CommonUtils.callSecuredAPI( RegistrationActivity.this, utils.getAPIServerURL() + Constants.REGISTER_ENDPOINT, HTTP_METHODS.POST, deviceInfoBuilder.getDeviceInfoPayload(), RegistrationActivity.this, Constants.REGISTER_REQUEST_CODE); } else { CommonDialogUtils.stopProgressDialog(progressDialog); CommonDialogUtils.showNetworkUnavailableMessage(RegistrationActivity.this); } }