From 7cbd0a859e2caf6d79a0d559c7d7d2508d7c14b9 Mon Sep 17 00:00:00 2001 From: "nikhil.a" Date: Mon, 12 Sep 2016 18:05:03 +0530 Subject: [PATCH] Updated Android Provider sample according to latest APIs. Change-Id: I3f8bab4b3992976648f6d20b7aa6b9aaedd83d65 Signed-off-by: nikhil.a Reviewed-on: https://gerrit.iotivity.org/gerrit/11693 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- .../com/sec/notiproviderexample/MainActivity.java | 12 +++++----- .../com/sec/notiproviderexample/ProviderProxy.java | 27 ++++++++++++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/MainActivity.java b/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/MainActivity.java index b2772bb..a5072f6 100755 --- a/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/MainActivity.java +++ b/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/MainActivity.java @@ -41,7 +41,7 @@ import org.iotivity.service.ns.common.MediaContents; public class MainActivity extends AppCompatActivity { private final String TAG = "NS_MAIN_ACTIVITY"; - private static final int MESSAGE_SUBSCRIPTION = 1; + private static final int CONSUMER_SUBSCRIBED = 1; private static final int MESSAGE_SYNC = 2; private static final int MESSAGE_NOTIFICATION = 3; @@ -68,16 +68,16 @@ public class MainActivity extends AppCompatActivity { @Override public void handleMessage(Message msg) { switch (msg.what) { - case MESSAGE_SUBSCRIPTION: - String subscriber = (String) msg.obj; - if(subscriber != null) - TvLog.append("Subscriber IP(" + ++subCnt + "): " + subscriber + "\n"); + case CONSUMER_SUBSCRIBED: + String ConsumerId = (String) msg.obj; + if(ConsumerId != null) + TvLog.append("Consumer Subscibed: " + ConsumerId + "\n"); break; case MESSAGE_SYNC: String sync = (String) msg.obj; if(sync != null) - TvLog.append("Sync-Read(Msg ID: " + sync + ")\n"); + TvLog.append("SyncInfo Received :" + sync + "\n"); break; default: diff --git a/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/ProviderProxy.java b/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/ProviderProxy.java index 789afe1..0c5aada 100755 --- a/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/ProviderProxy.java +++ b/service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/ProviderProxy.java @@ -23,7 +23,7 @@ package com.sec.notiproviderexample; import android.content.Context; -import android.os.Handler; +import android.os.*; import android.util.Log; import android.widget.Toast; @@ -33,6 +33,7 @@ import org.iotivity.base.OcResourceHandle; import org.iotivity.base.PlatformConfig; import org.iotivity.base.QualityOfService; import org.iotivity.base.ServiceType; +import org.iotivity.service.ns.common.Message; import org.iotivity.service.ns.provider.*; import org.iotivity.service.ns.common.*; @@ -40,7 +41,7 @@ import org.iotivity.service.ns.common.*; import java.util.HashMap; public class ProviderProxy - implements ProviderService.OnSubscriptionListener, ProviderService.OnSyncInfoListener{ + implements ProviderService.OnConsumerSubscribedListener, ProviderService.OnMessageSynchronizedListener{ private static final String TAG = "NS_PROVIDER_PROXY"; @@ -51,7 +52,7 @@ public class ProviderProxy private Handler mHandler = null; - private static final int MESSAGE_SUBSCRIPTION = 1; + private static final int CONSUMER_SUBSCRIBED = 1; private static final int MESSAGE_SYNC = 2; private static final int SYNC_READ = 0; @@ -97,7 +98,7 @@ public class ProviderProxy Log.i(TAG, "Start ProviderService -IN"); configurePlatform(); try{ - int result = ioTNotification.Start(policy, this, this); + int result = ioTNotification.start(this, this, policy, "Info"); Log.i(TAG, "Notification Start: " + result); } catch(Exception e){ @@ -115,7 +116,7 @@ public class ProviderProxy Log.e(TAG, "Exception: stopping presence when terminating NS server: " + e); } try{ - int result = ioTNotification.Stop(); + int result = ioTNotification.stop(); Log.i(TAG, "Notification Stop: " + result); } catch(Exception e){ @@ -129,7 +130,7 @@ public class ProviderProxy Log.i(TAG, "SendMessage ProviderService - IN"); try{ - int result = ioTNotification.SendMessage(notiMessage); + int result = ioTNotification.sendMessage(notiMessage); Log.i(TAG, "Notification Send Message: " + result); } catch(Exception e){ @@ -151,7 +152,7 @@ public class ProviderProxy if(msgMap.get(messageId) == SYNC_UNREAD) { try{ - ioTNotification.SendSyncInfo(messageId,syncType ); + ioTNotification.sendSyncInfo(messageId, syncType); Log.i(TAG, "Notification Sync " ); } catch(Exception e) { @@ -166,7 +167,7 @@ public class ProviderProxy public void EnableRemoteService(String servAdd) { Log.i(TAG, "EnableRemoteService ProviderService - IN"); try{ - int result = ioTNotification.EnableRemoteService(servAdd); + int result = ioTNotification.enableRemoteService(servAdd); Log.i(TAG, "Notification EnableRemoteService: "+ result ); } catch(Exception e) { @@ -178,7 +179,7 @@ public class ProviderProxy public void DisableRemoteService(String servAdd) { Log.i(TAG, "DisableRemoteService ProviderService - IN"); try{ - int result = ioTNotification.DisableRemoteService(servAdd); + int result = ioTNotification.disableRemoteService(servAdd); Log.i(TAG, "Notification DisableRemoteService: "+ result ); } catch(Exception e) { @@ -191,7 +192,7 @@ public class ProviderProxy { Log.i(TAG,"AcceptSubscription ProviderService - IN"); try{ - int result = consumer.AcceptSubscription(consumer, accepted); + int result = consumer.acceptSubscription(accepted); Log.i(TAG, "Notification AcceptSubscription: "+result ); } catch(Exception e) { @@ -204,12 +205,18 @@ public class ProviderProxy public void onConsumerSubscribed(Consumer consumer) { Log.i(TAG, "onConsumerSubscribed - IN"); AcceptSubscription(consumer, true); + android.os.Message msg = mHandler.obtainMessage(CONSUMER_SUBSCRIBED, + "Consumer Id: " + consumer.getConsumerId() ); + mHandler.sendMessage(msg); Log.i(TAG, "onConsumerSubscribed - OUT"); } @Override public void onMessageSynchronized(SyncInfo syncInfo) { Log.i(TAG, "Received SyncInfo with messageID: "+syncInfo.getMessageId()); + android.os.Message msg = mHandler.obtainMessage(MESSAGE_SYNC, + "Message Id: " + syncInfo.getMessageId() ); + mHandler.sendMessage(msg); } public HashMap getMsgMap() { -- 2.7.4