};
OcPlatformInfo platformInfo = null;
- try {
- platformInfo = new OcPlatformInfo("myPlatformID", "myManuName", "myManuUrl");
- } catch (OcException e) {
- Log.e(TAG, "Could not construct platformInfo. " + e.getMessage());
- assertTrue(false);
- }
+
+ platformInfo = new OcPlatformInfo("myPlatformID", "myManuName", "myManuUrl");
platformInfo.setModelNumber("myModelNumber");
platformInfo.setDateOfManufacture("myDateOfManufacture");
try {
//server
-
OcPlatform.registerPlatformInfo(platformInfo);
//client
OcPlatform.getPlatformInfo(
"",
- OcPlatform.MULTICAST_PREFIX + "/oic/p",
+ OcPlatform.WELL_KNOWN_PLATFORM_QUERY,
EnumSet.of(OcConnectivityType.CT_DEFAULT),
platformFoundListener);
}
};
- OcDeviceInfo devInfo = new OcDeviceInfo();
- devInfo.setDeviceName("myDeviceName");
+ OcDeviceInfo devInfo = new OcDeviceInfo("myDeviceName");
try {
//server
OcPlatform.registerDeviceInfo(devInfo);
-
//client
OcPlatform.getDeviceInfo(
"",
- OcPlatform.MULTICAST_PREFIX + OcPlatform.DEVICE_URI,
+ OcPlatform.WELL_KNOWN_DEVICE_QUERY,
EnumSet.of(OcConnectivityType.CT_DEFAULT),
deviceFoundListener);
PERSISTENT_BUFFER_REQUIRED("PERSISTENT_BUFFER_REQUIRED", ""),
INVALID_REQUEST_HANDLE("INVALID_REQUEST_HANDLE", ""),
INVALID_DEVICE_INFO("INVALID_DEVICE_INFO", ""),
- INVALID_PLATFORM_INFO_PLATFORMID("INVALID_PLATFORM_INFO_PLATFORMID",
- "PlatformID cannot be null or empty"),
- INVALID_PLATFORM_INFO_MANUFACTURER_NAME("INVALID_PLATFORM_INFO_MANUFACTURER_NAME",
- "ManufacturerName cannot be null, empty or greater than " +
- OcStackConfig.MAX_MANUFACTURER_NAME_LENGTH + " characters long"),
- INVALID_PLATFORM_INFO_PLATFORMID_MANUFACTURER_URL("INVALID_PLATFORM_INFO_MANUFACTURER_URL",
- "MANUFACTURER_URL cannot be null, empty or greater than " +
- OcStackConfig.MAX_MANUFACTURER_URL_LENGTH + " characters long"),
+
ERROR("ERROR", "Generic error"),
JNI_EXCEPTION("JNI_EXCEPTION", "Generic Java binder error"),
JNI_NO_NATIVE_OBJECT("JNI_NO_NATIVE_OBJECT", ""),
JNI_INVALID_VALUE("JNI_INVALID_VALUE", ""),
-
INVALID_CLASS_CAST("INVALID_CLASS_CAST", ""),;
private String error;
public class OcDeviceInfo {
- private String deviceName;
-
- public OcDeviceInfo() {
-
- deviceName = "";
- }
+ private String mDeviceName;
public OcDeviceInfo(String deviceName) {
- this.deviceName = deviceName;
+ this.mDeviceName = deviceName;
}
public String getDeviceName() {
-
- return deviceName;
- }
-
- public void setDeviceName(String deviceName) {
-
- this.deviceName = deviceName;
+ return mDeviceName;
}
}
public static final String GROUP_INTERFACE = "oic.mi.grp";
public static final String WELL_KNOWN_QUERY = "/oic/res";
- public static final String MULTICAST_PREFIX = "224.0.1.187:5683";
- public static final String MULTICAST_IP = "224.0.1.187";
- public static final int MULTICAST_PORT = 5683;
+ public static final String WELL_KNOWN_DEVICE_QUERY = "/oic/d";
+ public static final String WELL_KNOWN_PLATFORM_QUERY = "/oic/p";
public static final int DEFAULT_PRESENCE_TTL = 60;
- public static final String DEVICE_URI = "/oic/d";
public static final String PRESENCE_URI = "/oic/ad";
private static volatile boolean sIsPlatformInitialized = false;
resProperty |= prop.getValue();
}
- if(null == entityHandler){
+ if (null == entityHandler) {
entityHandler = new EntityHandler() {
@Override
public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest) {
OcPlatformInfo ocPlatformInfo) throws OcException {
OcPlatform.initCheck();
OcPlatform.registerPlatformInfo0(
- ocPlatformInfo.getPlatformID(),
+ ocPlatformInfo.getPlatformId(),
ocPlatformInfo.getManufacturerName(),
ocPlatformInfo.getManufacturerUrl(),
ocPlatformInfo.getModelNumber(),
package org.iotivity.base;
-import java.lang.Error;
+import java.security.InvalidParameterException;
public class OcPlatformInfo {
-
- private String platformID;
- private String manufacturerName;
- private String manufacturerUrl;
- private String modelNumber;
- private String dateOfManufacture;
- private String platformVersion;
- private String operatingSystemVersion;
- private String hardwareVersion;
- private String firmwareVersion;
- private String supportUrl;
- private String systemTime;
+ private String mPlatformId;
+ private String mManufacturerName;
+ private String mManufacturerUrl;
+ private String mModelNumber;
+ private String mDateOfManufacture;
+ private String mPlatformVersion;
+ private String mOperatingSystemVersion;
+ private String mHardwareVersion;
+ private String mFirmwareVersion;
+ private String mSupportUrl;
+ private String mSystemTime;
// construct OcPlatformInfo with mandatory fields which cannot be null
// manufacturerName cannot be > 16 chars
// manufacturerUrl cannot be > 32 chars
- protected OcPlatformInfo(String platformID, String manufacturerName,
- String manufacturerUrl) throws OcException {
- ErrorCode result = validatePlatformInfo(platformID, manufacturerName, manufacturerUrl);
- if (ErrorCode.OK == result) {
- this.platformID = platformID;
- this.manufacturerName = manufacturerName;
- this.manufacturerUrl = manufacturerUrl;
- } else {
- throw new OcException(result, result.getDescription());
- }
- }
-
- public ErrorCode validatePlatformInfo(String platformID, String manufacturerName,
- String manufacturerUrl) {
- // checks to see if the mandatory fields have non-null values or not
- if (platformID == null || platformID.isEmpty()) return ErrorCode.INVALID_PLATFORM_INFO_PLATFORMID;
- if (manufacturerName == null || manufacturerName.isEmpty() ||
- manufacturerName.length() > OcStackConfig.MAX_MANUFACTURER_NAME_LENGTH)
- return ErrorCode.INVALID_PLATFORM_INFO_MANUFACTURER_NAME;
- if (manufacturerUrl == null || manufacturerUrl.isEmpty() ||
- manufacturerUrl.length() > OcStackConfig.MAX_MANUFACTURER_URL_LENGTH)
- return ErrorCode.INVALID_PLATFORM_INFO_PLATFORMID_MANUFACTURER_URL;
- return ErrorCode.OK;
- }
-
- public String getPlatformID() {
- return platformID;
- }
-
- public void setPlatformID(String platformID) {
- this.platformID = platformID;
+ public OcPlatformInfo(String platformId, String manufacturerName,
+ String manufacturerUrl) {
+ this.mPlatformId = platformId;
+ this.mManufacturerName = manufacturerName;
+ this.mManufacturerUrl = manufacturerUrl;
+ }
+
+ public OcPlatformInfo(String platformId,
+ String manufacturerName,
+ String manufacturerUrl,
+ String modelNumber,
+ String dateOfManufacture,
+ String platformVersion,
+ String operatingSystemVersion,
+ String hardwareVersion,
+ String firmwareVersion,
+ String supportUrl,
+ String systemTime) {
+ this(platformId, manufacturerName, manufacturerUrl);
+ this.mModelNumber = modelNumber;
+ this.mDateOfManufacture = dateOfManufacture;
+ this.mPlatformVersion = platformVersion;
+ this.mOperatingSystemVersion = operatingSystemVersion;
+ this.mHardwareVersion = hardwareVersion;
+ this.mFirmwareVersion = firmwareVersion;
+ this.mSupportUrl = supportUrl;
+ this.mSystemTime = systemTime;
+ }
+
+ public String getPlatformId() {
+ return mPlatformId;
+ }
+
+ public void setPlatformId(String platformId) {
+ this.mPlatformId = platformId;
}
public String getManufacturerName() {
- return manufacturerName;
+ return mManufacturerName;
}
public void setManufacturerName(String manufacturerName) {
- this.manufacturerName = manufacturerName;
+ this.mManufacturerName = manufacturerName;
}
public String getManufacturerUrl() {
- return manufacturerUrl;
+ return mManufacturerUrl;
}
public void setManufacturerUrl(String manufacturerUrl) {
- this.manufacturerUrl = manufacturerUrl;
+ this.mManufacturerUrl = manufacturerUrl;
}
public String getModelNumber() {
- return modelNumber;
+ return mModelNumber;
}
public void setModelNumber(String modelNumber) {
- this.modelNumber = modelNumber;
+ this.mModelNumber = modelNumber;
}
public String getDateOfManufacture() {
- return dateOfManufacture;
+ return mDateOfManufacture;
}
public void setDateOfManufacture(String dateOfManufacture) {
- this.dateOfManufacture = dateOfManufacture;
+ this.mDateOfManufacture = dateOfManufacture;
}
public String getPlatformVersion() {
- return platformVersion;
+ return mPlatformVersion;
}
public void setPlatformVersion(String platformVersion) {
- this.platformVersion = platformVersion;
+ this.mPlatformVersion = platformVersion;
}
public String getOperatingSystemVersion() {
- return operatingSystemVersion;
+ return mOperatingSystemVersion;
}
public void setOperatingSystemVersion(String operatingSystemVersion) {
- this.operatingSystemVersion = operatingSystemVersion;
+ this.mOperatingSystemVersion = operatingSystemVersion;
}
public String getHardwareVersion() {
- return hardwareVersion;
+ return mHardwareVersion;
}
public void setHardwareVersion(String hardwareVersion) {
- this.hardwareVersion = hardwareVersion;
+ this.mHardwareVersion = hardwareVersion;
}
public String getFirmwareVersion() {
- return firmwareVersion;
+ return mFirmwareVersion;
}
public void setFirmwareVersion(String firmwareVersion) {
- this.firmwareVersion = firmwareVersion;
+ this.mFirmwareVersion = firmwareVersion;
}
public String getSupportUrl() {
- return supportUrl;
+ return mSupportUrl;
}
public void setSupportUrl(String supportUrl) {
- this.supportUrl = supportUrl;
+ this.mSupportUrl = supportUrl;
}
public String getSystemTime() {
- return systemTime;
+ return mSystemTime;
}
public void setSystemTime(String systemTime) {
- this.systemTime = systemTime;
+ this.mSystemTime = systemTime;
}
}
package org.iotivity.base;
-
public enum OcPlatformStatus {
UP(0),
DOWN(1),;
+++ /dev/null
-/*
- * //******************************************************************
- * //
- * // Copyright 2015 Intel Corporation.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- * //
- * // Licensed under the Apache License, Version 2.0 (the "License");
- * // you may not use this file except in compliance with the License.
- * // You may obtain a copy of the License at
- * //
- * // http://www.apache.org/licenses/LICENSE-2.0
- * //
- * // Unless required by applicable law or agreed to in writing, software
- * // distributed under the License is distributed on an "AS IS" BASIS,
- * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * // See the License for the specific language governing permissions and
- * // limitations under the License.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- */
-
-// This file contains all the variables which can be configured/modified as
-// per platform or specific product usage scenarios.
-
-package org.iotivity.base;
-
-public interface OcStackConfig {
- // max manufacturer name length for OcPlatformInfo supported by server
- public static final int MAX_MANUFACTURER_NAME_LENGTH = 16;
- // max manufacturer url length for OcPlatformInfo supported by server
- public static final int MAX_MANUFACTURER_URL_LENGTH = 32;
-}
\ No newline at end of file
--- /dev/null
+apply plugin: 'com.android.application'
+
+android {
+ compileSdkVersion 22
+ buildToolsVersion "22.0.1"
+
+ defaultConfig {
+ applicationId "org.iotivity.base.examples.devicediscoveryclient"
+ minSdkVersion 21
+ targetSdkVersion 22
+ versionCode 1
+ versionName "1.0"
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
+ }
+}
+
+dependencies {
+ compile fileTree(dir: 'libs', include: ['*.jar'])
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id=":devicediscoveryclient" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="examples" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+ <component name="FacetManager">
+ <facet type="android-gradle" name="Android-Gradle">
+ <configuration>
+ <option name="GRADLE_PROJECT_PATH" value=":devicediscoveryclient" />
+ </configuration>
+ </facet>
+ <facet type="android" name="Android">
+ <configuration>
+ <option name="SELECTED_BUILD_VARIANT" value="debug" />
+ <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
+ <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
+ <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
+ <option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
+ <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
+ <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugTestSources" />
+ <option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
+ <option name="ALLOW_USER_CONFIGURATION" value="false" />
+ <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
+ <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
+ <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
+ <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
+ </configuration>
+ </facet>
+ </component>
+ <component name="NewModuleRootManager" inherit-compiler-output="false">
+ <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
+ <output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+ <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+ <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
+ </content>
+ <orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" exported="" name="iotivity-armeabi-base-debug-unspecified" level="project" />
+ </component>
+</module>
\ No newline at end of file
--- /dev/null
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /home/rahul/sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.iotivity.base.examples" >
+
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.BLUETOOTH"/>
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
+ <uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
+ <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
+ <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+ <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
+
+ <application
+ android:allowBackup="true"
+ android:icon="@mipmap/iotivityicon"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme" >
+ <activity
+ android:screenOrientation="portrait"
+ android:name=".DeviceDiscoveryClient"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
--- /dev/null
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Intel Corporation.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * // http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+package org.iotivity.base.examples;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.text.method.ScrollingMovementMethod;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ScrollView;
+import android.widget.TextView;
+
+import org.iotivity.base.ModeType;
+import org.iotivity.base.OcConnectivityType;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ServiceType;
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This sample demonstrates the device discovery feature.
+ * The client queries for the device related information stored by the server.
+ */
+public class DeviceDiscoveryClient extends Activity implements
+ OcPlatform.OnDeviceFoundListener,
+ OcPlatform.OnPlatformFoundListener {
+ private void startDeviceDiscoveryClient() {
+ Context context = this;
+
+ PlatformConfig platformConfig = new PlatformConfig(
+ context,
+ ServiceType.IN_PROC,
+ ModeType.CLIENT,
+ "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+ 0, // Uses randomly available port
+ QualityOfService.LOW
+ );
+
+ msg("Configuring platform.");
+ OcPlatform.Configure(platformConfig);
+ sleep(1);
+
+ try {
+ msg("Querying for platform information...");
+ OcPlatform.getPlatformInfo("",
+ OcPlatform.WELL_KNOWN_PLATFORM_QUERY,
+ EnumSet.of(OcConnectivityType.CT_DEFAULT),
+ this);
+ } catch (OcException e) {
+ Log.e(TAG, e.toString());
+ msg("Failed to query for platform information");
+ }
+ sleep(2);
+
+ try {
+ msg("Querying for device information...");
+ OcPlatform.getDeviceInfo("",
+ OcPlatform.WELL_KNOWN_DEVICE_QUERY,
+ EnumSet.of(OcConnectivityType.CT_DEFAULT),
+ this);
+ } catch (OcException e) {
+ Log.e(TAG, e.toString());
+ msg("Failed to query for device information");
+ }
+ sleep(2);
+
+ enableStartButton();
+ printLine();
+ }
+
+ private final static Map<String, String> PLATFORM_INFO_KEYS = new HashMap<String, String>() {{
+ put("pi", "Platform ID: ");
+ put("mnmn", "Manufacturer name: ");
+ put("mnml", "Manufacturer url: ");
+ put("mnmo", "Manufacturer Model No: ");
+ put("mndt", "Manufactured Date: ");
+ put("mnpv", "Manufacturer Platform Version: ");
+ put("mnos", "Manufacturer OS version: ");
+ put("mnhw", "Manufacturer hardware version: ");
+ put("mnfv", "Manufacturer firmware version: ");
+ put("mnsl", "Manufacturer support url: ");
+ put("st", "Manufacturer system time: ");
+ }};
+
+ @Override
+ public synchronized void onPlatformFound(OcRepresentation ocRepresentation) {
+ msg("Platform Information received:");
+ try {
+ for (String key : PLATFORM_INFO_KEYS.keySet()) {
+ msg("\t" + PLATFORM_INFO_KEYS.get(key) + ocRepresentation.getValue(key));
+ }
+ } catch (OcException e) {
+ Log.e(TAG, e.toString());
+ msg("Failed to read platform info values.");
+ }
+
+ printLine();
+ }
+
+ private final static Map<String, String> DEVICE_INFO_KEYS = new HashMap<String, String>() {{
+ put("di", "Device ID: ");
+ put("n", "Device name: ");
+ put("lcv", "Spec version url: ");
+ put("dmv", "Data Model: ");
+ }};
+
+ @Override
+ public synchronized void onDeviceFound(OcRepresentation ocRepresentation) {
+ msg("Device Information received:");
+ try {
+ for (String key : DEVICE_INFO_KEYS.keySet()) {
+ msg("\t" + DEVICE_INFO_KEYS.get(key) + ocRepresentation.getValue(key));
+ }
+ } catch (OcException e) {
+ Log.e(TAG, e.toString());
+ msg("Failed to read device info values.");
+ }
+
+ printLine();
+ }
+
+ //******************************************************************************
+ // End of the OIC specific code
+ //******************************************************************************
+
+ private final static String TAG = DeviceDiscoveryClient.class.getSimpleName();
+ private TextView mConsoleTextView;
+ private ScrollView mScrollView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_device_discovery_client);
+
+ mConsoleTextView = (TextView) findViewById(R.id.consoleTextView);
+ mConsoleTextView.setMovementMethod(new ScrollingMovementMethod());
+ mScrollView = (ScrollView) findViewById(R.id.scrollView);
+ mScrollView.fullScroll(View.FOCUS_DOWN);
+ final Button button = (Button) findViewById(R.id.button);
+
+ if (null == savedInstanceState) {
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ button.setText("Re-start");
+ button.setEnabled(false);
+ new Thread(new Runnable() {
+ public void run() {
+ startDeviceDiscoveryClient();
+ }
+ }).start();
+ }
+ });
+ } else {
+ String consoleOutput = savedInstanceState.getString("consoleOutputString");
+ mConsoleTextView.setText(consoleOutput);
+ }
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putString("consoleOutputString", mConsoleTextView.getText().toString());
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
+
+ String consoleOutput = savedInstanceState.getString("consoleOutputString");
+ mConsoleTextView.setText(consoleOutput);
+ }
+
+ private void enableStartButton() {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ Button button = (Button) findViewById(R.id.button);
+ button.setEnabled(true);
+ }
+ });
+ }
+
+ private void sleep(int seconds) {
+ try {
+ Thread.sleep(seconds * 1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ Log.e(TAG, e.toString());
+ }
+ }
+
+ private void msg(final String text) {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ mConsoleTextView.append("\n");
+ mConsoleTextView.append(text);
+ mScrollView.fullScroll(View.FOCUS_DOWN);
+ }
+ });
+ Log.i(TAG, text);
+ }
+
+ private void printLine() {
+ msg("------------------------------------------------------------------------");
+ }
+}
--- /dev/null
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
+ android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:orientation="vertical"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".DeviceDiscoveryClient">
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/button"
+ android:layout_centerHorizontal="true"
+ android:textOff="Start"
+ android:textOn="Stop"
+ android:layout_alignParentEnd="true"
+ android:layout_alignParentStart="true"
+ android:text="Start" />
+ <ScrollView
+ android:layout_below="@id/button"
+ android:layout_above="@+id/imageView"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:fillViewport="true"
+ android:id="@+id/scrollView">
+ <TextView android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/consoleTextView" />
+ </ScrollView>
+ <ImageView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/imageView"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentEnd="true"
+ android:layout_alignParentStart="true"
+ android:src="@drawable/iotivitylogo" />
+</RelativeLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <style name="AppTheme" parent="android:Theme.Material.Light">
+ </style>
+</resources>
--- /dev/null
+<resources>
+ <!-- Example customization of dimensions originally defined in res/values/dimens.xml
+ (such as screen margins) for screens with more than 820dp of available width. This
+ would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
+ <dimen name="activity_horizontal_margin">64dp</dimen>
+</resources>
--- /dev/null
+<resources>
+ <!-- Default screen margins, per the Android Design guidelines. -->
+ <dimen name="activity_horizontal_margin">16dp</dimen>
+ <dimen name="activity_vertical_margin">16dp</dimen>
+</resources>
--- /dev/null
+<resources>
+ <string name="app_name">Device Discovery Client</string>
+</resources>
--- /dev/null
+<resources>
+
+ <!-- Base application theme. -->
+ <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+ <!-- Customize your theme here. -->
+ </style>
+
+</resources>
--- /dev/null
+apply plugin: 'com.android.application'
+
+android {
+ compileSdkVersion 22
+ buildToolsVersion "22.0.1"
+
+ defaultConfig {
+ applicationId "org.iotivity.base.examples.devicediscoveryserver"
+ minSdkVersion 21
+ targetSdkVersion 22
+ versionCode 1
+ versionName "1.0"
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
+ }
+}
+
+dependencies {
+ compile fileTree(dir: 'libs', include: ['*.jar'])
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id=":devicediscoveryserver" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="examples" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+ <component name="FacetManager">
+ <facet type="android-gradle" name="Android-Gradle">
+ <configuration>
+ <option name="GRADLE_PROJECT_PATH" value=":devicediscoveryserver" />
+ </configuration>
+ </facet>
+ <facet type="android" name="Android">
+ <configuration>
+ <option name="SELECTED_BUILD_VARIANT" value="debug" />
+ <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
+ <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
+ <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
+ <option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
+ <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
+ <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugTestSources" />
+ <option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
+ <option name="ALLOW_USER_CONFIGURATION" value="false" />
+ <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
+ <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
+ <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
+ <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
+ </configuration>
+ </facet>
+ </component>
+ <component name="NewModuleRootManager" inherit-compiler-output="false">
+ <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
+ <output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+ <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+ <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
+ </content>
+ <orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" exported="" name="iotivity-armeabi-base-debug-unspecified" level="project" />
+ </component>
+</module>
\ No newline at end of file
--- /dev/null
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /home/rahul/sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.iotivity.base.examples" >
+
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.BLUETOOTH"/>
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
+ <uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
+ <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
+ <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+ <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
+
+ <application
+ android:allowBackup="true"
+ android:icon="@mipmap/iotivityicon"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme" >
+ <activity
+ android:screenOrientation="portrait"
+ android:name=".DeviceDiscoveryServer"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
--- /dev/null
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Intel Corporation.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * // http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+package org.iotivity.base.examples;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.text.method.ScrollingMovementMethod;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ScrollView;
+import android.widget.TextView;
+
+import org.iotivity.base.ModeType;
+import org.iotivity.base.OcDeviceInfo;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcPlatformInfo;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ServiceType;
+
+/**
+ * This sample demonstrates platform and device discovery feature.
+ * The server sets the platform and device related info. which can be later retrieved by a client.
+ */
+public class DeviceDiscoveryServer extends Activity {
+
+ private void startDeviceDiscoveryServer() {
+ Context context = this;
+
+ PlatformConfig platformConfig = new PlatformConfig(
+ context,
+ ServiceType.IN_PROC,
+ ModeType.SERVER,
+ "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
+ 0, // Uses randomly available port
+ QualityOfService.LOW
+ );
+
+ msg("Configuring platform.");
+ OcPlatform.Configure(platformConfig);
+
+ OcDeviceInfo deviceInfo = new OcDeviceInfo("myDeviceName");
+ try {
+ msg("Registering device info");
+ OcPlatform.registerDeviceInfo(deviceInfo);
+ } catch (OcException e) {
+ Log.e(TAG, e.toString());
+ msg("Failed to register device info.");
+ }
+
+ OcPlatformInfo platformInfo = new OcPlatformInfo(
+ "myPlatformId", //Platform ID
+ "myManufactName", //Manufacturer Name
+ "www.myurl.com", //Manufacturer URL
+ "myModelNumber", //Model Number
+ "myDateOfManufacture", //Date of Manufacture
+ "myPlatformVersion", //Platform Version
+ "Manufacturer OS version", //Operating System Version
+ "myHardwareVersion", //Hardware Version
+ "myFirmwareVersion", //Firmware Version
+ "www.mysupporturl.com", //Support URL
+ String.valueOf(System.currentTimeMillis()) // System Time
+ );
+ try {
+ msg("Registering platform info");
+ OcPlatform.registerPlatformInfo(platformInfo);
+ } catch (OcException e) {
+ Log.e(TAG, e.toString());
+ msg("Failed to register platform info.");
+ }
+
+ msg("Waiting for the requests...");
+ printLine();
+ }
+
+ //******************************************************************************
+ // End of the OIC specific code
+ //******************************************************************************
+
+ private final static String TAG = DeviceDiscoveryServer.class.getSimpleName();
+ private TextView mConsoleTextView;
+ private ScrollView mScrollView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_device_discovery_server);
+
+ mConsoleTextView = (TextView) findViewById(R.id.consoleTextView);
+ mConsoleTextView.setMovementMethod(new ScrollingMovementMethod());
+ mScrollView = (ScrollView) findViewById(R.id.scrollView);
+ mScrollView.fullScroll(View.FOCUS_DOWN);
+ final Button button = (Button) findViewById(R.id.button);
+
+ if (null == savedInstanceState) {
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ button.setEnabled(false);
+ new Thread(new Runnable() {
+ public void run() {
+ startDeviceDiscoveryServer();
+ }
+ }).start();
+ }
+ });
+ } else {
+ String consoleOutput = savedInstanceState.getString("consoleOutputString");
+ mConsoleTextView.setText(consoleOutput);
+ }
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putString("consoleOutputString", mConsoleTextView.getText().toString());
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
+
+ String consoleOutput = savedInstanceState.getString("consoleOutputString");
+ mConsoleTextView.setText(consoleOutput);
+ }
+
+ private void msg(final String text) {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ mConsoleTextView.append("\n");
+ mConsoleTextView.append(text);
+ mScrollView.fullScroll(View.FOCUS_DOWN);
+ }
+ });
+ Log.i(TAG, text);
+ }
+
+ private void printLine() {
+ msg("------------------------------------------------------------------------");
+ }
+}
--- /dev/null
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
+android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
+android:orientation="vertical"
+android:paddingRight="@dimen/activity_horizontal_margin"
+android:paddingTop="@dimen/activity_vertical_margin"
+android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".DeviceDiscoveryServer">
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/button"
+ android:layout_centerHorizontal="true"
+ android:textOff="Start"
+ android:textOn="Stop"
+ android:layout_alignParentEnd="true"
+ android:layout_alignParentStart="true"
+ android:text="Start" />
+ <ScrollView
+ android:layout_below="@id/button"
+ android:layout_above="@+id/imageView"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:fillViewport="true"
+ android:id="@+id/scrollView">
+ <TextView android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/consoleTextView" />
+ </ScrollView>
+ <ImageView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/imageView"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentEnd="true"
+ android:layout_alignParentStart="true"
+ android:src="@drawable/iotivitylogo" />
+</RelativeLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <style name="AppTheme" parent="android:Theme.Material.Light">
+ </style>
+</resources>
--- /dev/null
+<resources>
+ <!-- Example customization of dimensions originally defined in res/values/dimens.xml
+ (such as screen margins) for screens with more than 820dp of available width. This
+ would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
+ <dimen name="activity_horizontal_margin">64dp</dimen>
+</resources>
--- /dev/null
+<resources>
+ <!-- Default screen margins, per the Android Design guidelines. -->
+ <dimen name="activity_horizontal_margin">16dp</dimen>
+ <dimen name="activity_vertical_margin">16dp</dimen>
+</resources>
--- /dev/null
+<resources>
+ <string name="app_name">Device Discovery Server</string>
+</resources>
--- /dev/null
+<resources>
+
+ <!-- Base application theme. -->
+ <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+ <!-- Customize your theme here. -->
+ </style>
+
+</resources>
buildToolsVersion "22.0.1"
defaultConfig {
- applicationId "org.iotivity.base.examples"
+ applicationId "org.iotivity.base.examples.presenceclient"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="org.iotivity.base.examples" >
+ package="org.iotivity.base.examples">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- <uses-permission android:name="android.permission.BLUETOOTH"/>
- <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
- <uses-permission android:name="android.permission.INTERNET"/>
- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
- <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
- <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
- <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
+ <uses-permission android:name="android.permission.BLUETOOTH" />
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+ <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
+ <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+ <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/iotivityicon"
android:label="@string/app_name"
- android:theme="@style/AppTheme" >
+ android:theme="@style/AppTheme">
<activity
- android:screenOrientation="portrait"
android:name=".PresenceClient"
- android:label="@string/app_name" >
+ android:label="@string/app_name"
+ android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
import org.iotivity.base.OcPresenceHandle;
import org.iotivity.base.OcPresenceStatus;
import org.iotivity.base.OcResource;
-import org.iotivity.base.OcResourceHandle;
import org.iotivity.base.PlatformConfig;
import org.iotivity.base.QualityOfService;
-import org.iotivity.base.ResourceProperty;
import org.iotivity.base.ServiceType;
import java.util.EnumSet;
-import java.util.LinkedList;
-import java.util.List;
-
+/**
+ * A client example for presence notification
+ */
public class PresenceClient extends Activity implements
OcPlatform.OnResourceFoundListener,
OcPlatform.OnPresenceListener {
+ private final static String TAG = PresenceClient.class.getSimpleName();
private OcResource mResource;
private OcPresenceHandle mPresenceHandle;
+ private TextView mConsoleTextView;
+ private ScrollView mScrollView;
private void startPresenceClient() {
Context context = this;
enableStartStopButton();
}
+ //******************************************************************************
+ // End of the OIC specific code
+ //******************************************************************************
+
@Override
public synchronized void onResourceFound(OcResource foundResource) {
String resourceUri = foundResource.getUri();
enableStartStopButton();
}
- //******************************************************************************
- // End of the OIC specific code
- //******************************************************************************
-
- private final static String TAG = PresenceClient.class.getSimpleName();
- private TextView mConsoleTextView;
- private ScrollView mScrollView;
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
});
- }
-
- if (null != savedInstanceState) {
+ } else {
String consoleOutput = savedInstanceState.getString("consoleOutputString");
mConsoleTextView.setText(consoleOutput);
boolean buttonCheked = savedInstanceState.getBoolean("toggleButtonChecked");
msg("------------------------------------------------------------------------");
}
- private void sleep(int seconds) {
- try {
- Thread.sleep(seconds * 1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- Log.e(TAG, e.toString());
- }
- }
-
private void enableStartStopButton() {
runOnUiThread(new Runnable() {
public void run() {
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
- android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
android:orientation="vertical"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".PresenceClient">
+ tools:context=".PresenceClient">
+
<ToggleButton
+ android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:id="@+id/toggleButton"
+ android:layout_alignParentEnd="true"
+ android:layout_alignParentStart="true"
android:layout_centerHorizontal="true"
android:textOff="Start"
- android:textOn="Stop"
- android:layout_alignParentEnd="true"
- android:layout_alignParentStart="true" />
+ android:textOn="Stop" />
+
<ScrollView
- android:layout_below="@id/toggleButton"
- android:layout_above="@+id/imageView"
+ android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:fillViewport="true"
- android:id="@+id/scrollView">
- <TextView android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/consoleTextView" />
+ android:layout_above="@+id/imageView"
+ android:layout_below="@id/toggleButton"
+ android:fillViewport="true">
+
+ <TextView
+ android:id="@+id/consoleTextView"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
</ScrollView>
+
<ImageView
+ android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:id="@+id/imageView"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <style name="AppTheme" parent="android:Theme.Material.Light">
- </style>
+
+ <style name="AppTheme" parent="android:Theme.Material.Light"></style>
</resources>
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
-
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.ToggleButton;
-import org.iotivity.base.EntityHandlerResult;
import org.iotivity.base.ModeType;
import org.iotivity.base.OcException;
import org.iotivity.base.OcPlatform;
import org.iotivity.base.OcResourceHandle;
-import org.iotivity.base.OcResourceRequest;
import org.iotivity.base.PlatformConfig;
import org.iotivity.base.QualityOfService;
import org.iotivity.base.ResourceProperty;
import org.iotivity.base.ServiceType;
import java.util.EnumSet;
-import java.util.LinkedList;
-import java.util.List;
-
+/**
+ * A server example for presence notification
+ */
public class PresenceServer extends Activity {
private OcResourceHandle mResourceHandle;
}
}
});
- }
-
- if (null != savedInstanceState) {
+ } else {
String consoleOutput = savedInstanceState.getString("consoleOutputString");
mConsoleTextView.setText(consoleOutput);
boolean buttonCheked = savedInstanceState.getBoolean("toggleButtonChecked");
-include ':simpleserver', ':simpleclient', ':message', ':fridgeserver', ':fridgeclient', ':guiclient', ':presenceserver', ':presenceclient'
+include ':simpleserver', ':simpleclient', ':message', ':fridgeserver', ':fridgeclient', ':guiclient', ':presenceserver', ':presenceclient', ':devicediscoveryclient', ':devicediscoveryserver', ':iotivity-armeabi-base-debug'