OcPlatform.Configure(platformConfig);
try {
+ msg("Subscribing to multicast presence");
+ OcPlatform.subscribePresence(OcPlatform.PRESENCE_URI,
+ EnumSet.of(OcConnectivityType.CT_DEFAULT), this);
+ } catch (OcException e) {
+ Log.e(TAG, e.toString());
+ msg("Failed to subscribe to multicast presence");
+ }
+
+ try {
msg("Finding Resource...");
OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY,
EnumSet.of(OcConnectivityType.CT_DEFAULT), this);
*/
public class PresenceServer extends Activity {
private OcResourceHandle mResourceHandle;
+ private int mPresenceCount = 0;
+ private final int mMaxCount = 10;
private void startPresenceServer() {
Context context = this;
enableStartStopButton();
}
+ private void startPresence()
+ {
+ try {
+ msg("Starting presence notifications (" + mPresenceCount + " / " + mMaxCount + ")");
+ OcPlatform.startPresence(OcPlatform.DEFAULT_PRESENCE_TTL);
+ sleep(3);
+ } catch (OcException e) {
+ Log.e(TAG, e.toString());
+ msg("Error: " + e.toString());
+ }
+ }
+
/**
* This function internally calls registerResource API.
*/
new Thread(new Runnable() {
public void run() {
startPresenceServer();
+
+ mPresenceCount = 0;
+ while(mPresenceCount++ < mMaxCount)
+ {
+ startPresence();
+ }
+ stopPresenceServer();
}
}).start();
} else {
new Thread(new Runnable() {
public void run() {
+ mPresenceCount = 10;
stopPresenceServer();
}
}).start();