Update Android Sample App to enable findResource on unicast BLE
authorjihwan.seo <jihwan.seo@samsung.com>
Tue, 13 Dec 2016 08:43:17 +0000 (17:43 +0900)
committerRick Bell <richard.s.bell@intel.com>
Wed, 14 Dec 2016 23:37:03 +0000 (23:37 +0000)
since findResource on multicast in BLE is not supported anymore,
it should be updated

Change-Id: Ie26c3b50d9f9624a392931027d546bd7a040d6bc
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/15559
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Larry Sachs <larry.j.sachs@intel.com>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-by: Rick Bell <richard.s.bell@intel.com>
java/examples-android/simplebase/src/main/java/org/iotivity/base/examples/BluetoothFragment.java
java/examples-android/simplebase/src/main/java/org/iotivity/base/examples/Common.java
java/examples-android/simplebase/src/main/java/org/iotivity/base/examples/MessageFragment.java

index 1d21865..21e727e 100644 (file)
@@ -266,6 +266,7 @@ public class BluetoothFragment extends Fragment implements
                 sb.append("Set Connect with : ");
                 try {
                     final String address = mBluetoothDevices.get(pos).getAddress();
+                    Common.setLeAddress(address);
                     CaInterface.setAutoConnectionDevice(address);
                     OcPlatform.OnResourceFoundListener resourceFoundListener =
                             new OcPlatform.OnResourceFoundListener() {
index 3da184e..8220c02 100644 (file)
@@ -24,6 +24,7 @@ package org.iotivity.base.examples;
 
 import android.content.Context;
 import android.widget.Toast;
+import android.util.Log;
 
 import org.iotivity.base.OcPlatform;
 import org.iotivity.base.ResourceProperty;
@@ -39,6 +40,7 @@ import java.util.Locale;
  */
 public class Common {
 
+    private static final String TAG               = "OIC_SIMPLE_COMMON";
     public static final int    DATA_SIZE          = 3000;
     public static String       HOST               = "coap+tcp://192.168.0.1:5683";
     public static final String COAP_TCP           = "coap+tcp://";
@@ -67,6 +69,8 @@ public class Common {
     public final static String MQ_DEFAULT_TOPIC_URI = "/oic/ps/cleanroom";
     public final static String MQ_BROKER_URI = "/oic/ps";
 
+    private static String mLeAddress = null;
+
     public static String getDateCurrentTimeZone() {
         StringBuilder sb = new StringBuilder();
         try {
@@ -86,5 +90,17 @@ public class Common {
     public static void showToast(Context context, String msg) {
         Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
     }
+
+    public static void setLeAddress(String address)
+    {
+        Log.i(TAG, "setLeAddress : " + address.toString());
+        mLeAddress = address;
+    }
+
+    public static String getLeAddress()
+    {
+        Log.i(TAG, "getLeAddress : " + mLeAddress);
+        return mLeAddress;
+    }
 }
 
index 6c11b2e..cc6ed71 100644 (file)
@@ -169,6 +169,17 @@ public class MessageFragment extends Fragment implements OcResource.OnGetListene
                                 OcPlatform.WELL_KNOWN_QUERY,
                                 EnumSet.of(OcConnectivityType.CT_ADAPTER_IP),
                                 resourceFoundListener, mQos);
+                    } else if (OcConnectivityType.CT_ADAPTER_GATT_BTLE == connectivityType) {
+                        if (null != Common.getLeAddress())
+                        {
+                            OcPlatform.findResource("",
+                                    Common.getLeAddress() + OcPlatform.WELL_KNOWN_QUERY,
+                                    EnumSet.of(OcConnectivityType.CT_ADAPTER_GATT_BTLE),
+                                    resourceFoundListener, QualityOfService.LOW);
+                        } else {
+                            Common.showToast(mContext, "Please scan ble device");
+                            Log.e(TAG, "invalid ble device");
+                        }
                     } else {
                         OcPlatform.findResource("",
                                 OcPlatform.WELL_KNOWN_QUERY,