Browse Source

<nursId改成int类型>

weizhengliang 5 years ago
parent
commit
6c70f78482

+ 7 - 0
app/src/main/java/com/wdkl/nursewatch/presentation/ui/activities/HomeActivity.java

@@ -290,6 +290,7 @@ public class HomeActivity extends BaseActivity implements View.OnClickListener {
         }
 
         loginMachineId = SharedPreferencesUtil.getStringSp( SharedPreferencesUtil.LOGIN_MACHINEID);
+        String nurseID = SharedPreferencesUtil.getStringSp(SharedPreferencesUtil.LOGIN_NURSE_ID);
         String nurseName = SharedPreferencesUtil.getStringSp(SharedPreferencesUtil.LOGIN_NURSE_NAME);
         if (StringUtils.notEmpty(nurseName)) {
             tv_nurse_name.setText(nurseName);
@@ -307,6 +308,12 @@ public class HomeActivity extends BaseActivity implements View.OnClickListener {
                 tv_home_times.setTextColor(Color.WHITE);
             }
 
+            //启动蓝牙信标扫描服务
+            final Intent intent = new Intent(this, BeaconService.class);
+            intent.putExtra(BeaconService.SERVER_ID_KEY, loginMachineId);
+            intent.putExtra(BeaconService.NURSE_ID_KEY, nurseID);
+            intent.putExtra(BeaconService.NURSE_NAME_KEY, nurseName);
+            startService(intent);
         } else {
             Constants.IS_LOGOUT = true;
         }

+ 11 - 2
app/src/main/java/com/wdkl/nursewatch/service/BeaconService.java

@@ -8,6 +8,8 @@ import android.os.RemoteException;
 import android.support.annotation.Nullable;
 import android.util.Log;
 
+import com.wdkl.nursewatch.utils.StringUtils;
+
 import org.altbeacon.beacon.Beacon;
 import org.altbeacon.beacon.BeaconConsumer;
 import org.altbeacon.beacon.BeaconManager;
@@ -51,7 +53,7 @@ public class BeaconService extends Service implements BeaconConsumer, RangeNotif
 
     private String serverId;
 
-    private String nurseId;
+    private int nurseId;
 
     private String nurseName;
 
@@ -90,7 +92,13 @@ public class BeaconService extends Service implements BeaconConsumer, RangeNotif
     public int onStartCommand(Intent intent, int flags, int startId) {
 
         serverId = intent.getStringExtra(SERVER_ID_KEY);
-        nurseId = intent.getStringExtra(NURSE_ID_KEY);
+        String ID = intent.getStringExtra(NURSE_ID_KEY);
+        try {
+            nurseId = Integer.valueOf(ID);
+        } catch (Exception e) {
+            nurseId = -1;
+            e.printStackTrace();
+        }
         nurseName = intent.getStringExtra(NURSE_NAME_KEY);
 
         return super.onStartCommand(intent, flags, startId);
@@ -111,6 +119,7 @@ public class BeaconService extends Service implements BeaconConsumer, RangeNotif
     @Override
     public void didRangeBeaconsInRegion(Collection<Beacon> collection, Region region) {
         BEACON_HANDLER.execute(() -> {
+            //Log.d("wzl", "didRangeBeaconsInRegion size: " + collection.size());
             if (collection.size() > 0) {
                 final JSONObject obj = new JSONObject();
                 try {