Updated Android Provider sample according to latest APIs.
authornikhil.a <nikhil.a7@samsung.com>
Mon, 12 Sep 2016 12:35:03 +0000 (18:05 +0530)
committerUze Choi <uzchoi@samsung.com>
Tue, 13 Sep 2016 04:51:57 +0000 (04:51 +0000)
Change-Id: I3f8bab4b3992976648f6d20b7aa6b9aaedd83d65
Signed-off-by: nikhil.a <nikhil.a7@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11693
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/MainActivity.java
service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/ProviderProxy.java

index b2772bb..a5072f6 100755 (executable)
@@ -41,7 +41,7 @@ import org.iotivity.service.ns.common.MediaContents;
 public class MainActivity extends AppCompatActivity {\r
 \r
     private final String TAG = "NS_MAIN_ACTIVITY";\r
-    private static final int MESSAGE_SUBSCRIPTION = 1;\r
+    private static final int CONSUMER_SUBSCRIBED = 1;\r
     private static final int MESSAGE_SYNC = 2;\r
     private static final int MESSAGE_NOTIFICATION = 3;\r
 \r
@@ -68,16 +68,16 @@ public class MainActivity extends AppCompatActivity {
         @Override\r
         public void handleMessage(Message msg) {\r
             switch (msg.what) {\r
-                case MESSAGE_SUBSCRIPTION:\r
-                    String subscriber = (String) msg.obj;\r
-                    if(subscriber != null)\r
-                        TvLog.append("Subscriber IP(" + ++subCnt + "): " + subscriber + "\n");\r
+                case CONSUMER_SUBSCRIBED:\r
+                    String ConsumerId = (String) msg.obj;\r
+                    if(ConsumerId != null)\r
+                        TvLog.append("Consumer Subscibed: " + ConsumerId + "\n");\r
                     break;\r
 \r
                 case MESSAGE_SYNC:\r
                     String sync = (String) msg.obj;\r
                     if(sync != null)\r
-                        TvLog.append("Sync-Read(Msg ID: " + sync + ")\n");\r
+                        TvLog.append("SyncInfo Received :" + sync + "\n");\r
                     break;\r
 \r
                 default:\r
index 789afe1..0c5aada 100755 (executable)
@@ -23,7 +23,7 @@
 package com.sec.notiproviderexample;\r
 \r
 import android.content.Context;\r
-import android.os.Handler;\r
+import android.os.*;\r
 import android.util.Log;\r
 import android.widget.Toast;\r
 \r
@@ -33,6 +33,7 @@ import org.iotivity.base.OcResourceHandle;
 import org.iotivity.base.PlatformConfig;\r
 import org.iotivity.base.QualityOfService;\r
 import org.iotivity.base.ServiceType;\r
+import org.iotivity.service.ns.common.Message;\r
 import org.iotivity.service.ns.provider.*;\r
 import org.iotivity.service.ns.common.*;\r
 \r
@@ -40,7 +41,7 @@ import org.iotivity.service.ns.common.*;
 import java.util.HashMap;\r
 \r
 public class ProviderProxy\r
-        implements ProviderService.OnSubscriptionListener, ProviderService.OnSyncInfoListener{\r
+        implements ProviderService.OnConsumerSubscribedListener, ProviderService.OnMessageSynchronizedListener{\r
 \r
     private static final String TAG = "NS_PROVIDER_PROXY";\r
 \r
@@ -51,7 +52,7 @@ public class ProviderProxy
 \r
     private Handler mHandler = null;\r
 \r
-    private static final int MESSAGE_SUBSCRIPTION = 1;\r
+    private static final int CONSUMER_SUBSCRIBED = 1;\r
     private static final int MESSAGE_SYNC = 2;\r
 \r
     private static final int SYNC_READ = 0;\r
@@ -97,7 +98,7 @@ public class ProviderProxy
         Log.i(TAG, "Start ProviderService -IN");\r
         configurePlatform();\r
         try{\r
-            int result =  ioTNotification.Start(policy, this, this);\r
+            int result =  ioTNotification.start(this, this, policy, "Info");\r
             Log.i(TAG, "Notification Start: " + result);\r
         }\r
         catch(Exception e){\r
@@ -115,7 +116,7 @@ public class ProviderProxy
             Log.e(TAG, "Exception: stopping presence when terminating NS server: " + e);\r
         }\r
         try{\r
-            int result =  ioTNotification.Stop();\r
+            int result =  ioTNotification.stop();\r
             Log.i(TAG, "Notification Stop: " + result);\r
         }\r
         catch(Exception e){\r
@@ -129,7 +130,7 @@ public class ProviderProxy
         Log.i(TAG, "SendMessage ProviderService - IN");\r
 \r
         try{\r
-            int result =  ioTNotification.SendMessage(notiMessage);\r
+            int result =  ioTNotification.sendMessage(notiMessage);\r
             Log.i(TAG, "Notification Send Message: " + result);\r
         }\r
         catch(Exception e){\r
@@ -151,7 +152,7 @@ public class ProviderProxy
             if(msgMap.get(messageId) == SYNC_UNREAD)\r
             {\r
                 try{\r
-                    ioTNotification.SendSyncInfo(messageId,syncType );\r
+                    ioTNotification.sendSyncInfo(messageId, syncType);\r
                     Log.i(TAG, "Notification Sync " );\r
                 }\r
                 catch(Exception e) {\r
@@ -166,7 +167,7 @@ public class ProviderProxy
     public void EnableRemoteService(String servAdd) {\r
         Log.i(TAG, "EnableRemoteService ProviderService - IN");\r
         try{\r
-            int result = ioTNotification.EnableRemoteService(servAdd);\r
+            int result = ioTNotification.enableRemoteService(servAdd);\r
             Log.i(TAG, "Notification EnableRemoteService: "+ result );\r
         }\r
         catch(Exception e) {\r
@@ -178,7 +179,7 @@ public class ProviderProxy
     public void DisableRemoteService(String servAdd) {\r
         Log.i(TAG, "DisableRemoteService ProviderService - IN");\r
         try{\r
-            int result = ioTNotification.DisableRemoteService(servAdd);\r
+            int result = ioTNotification.disableRemoteService(servAdd);\r
             Log.i(TAG, "Notification DisableRemoteService: "+ result );\r
         }\r
         catch(Exception e) {\r
@@ -191,7 +192,7 @@ public class ProviderProxy
     {\r
         Log.i(TAG,"AcceptSubscription ProviderService - IN");\r
         try{\r
-            int result = consumer.AcceptSubscription(consumer, accepted);\r
+            int result = consumer.acceptSubscription(accepted);\r
             Log.i(TAG, "Notification AcceptSubscription: "+result );\r
         }\r
         catch(Exception e) {\r
@@ -204,12 +205,18 @@ public class ProviderProxy
     public void onConsumerSubscribed(Consumer consumer) {\r
         Log.i(TAG, "onConsumerSubscribed - IN");\r
         AcceptSubscription(consumer, true);\r
+        android.os.Message msg = mHandler.obtainMessage(CONSUMER_SUBSCRIBED,\r
+                "Consumer Id: " + consumer.getConsumerId()  );\r
+        mHandler.sendMessage(msg);\r
         Log.i(TAG, "onConsumerSubscribed - OUT");\r
     }\r
 \r
     @Override\r
     public void onMessageSynchronized(SyncInfo syncInfo) {\r
         Log.i(TAG, "Received SyncInfo with messageID: "+syncInfo.getMessageId());\r
+        android.os.Message msg = mHandler.obtainMessage(MESSAGE_SYNC,\r
+                "Message Id: " + syncInfo.getMessageId()  );\r
+        mHandler.sendMessage(msg);\r
     }\r
 \r
     public HashMap<String, Integer> getMsgMap() {\r