Explorar o código

添加 service 实时监听 websocket状态 并和服务器应答心跳
添加网络不可用时 进行亮屏解锁 自动联网
暂时注释所有蓝牙服务
现用网址是 自己公司外网测试网址

wangjk %!s(int64=4) %!d(string=hai) anos
pai
achega
601852032c

BIN=BIN
.idea/caches/build_file_checksums.ser


BIN=BIN
.idea/caches/gradle_models.ser


+ 3 - 0
.idea/gradle.xml

@@ -3,6 +3,9 @@
   <component name="GradleSettings">
     <option name="linkedExternalProjectsSettings">
       <GradleProjectSettings>
+        <compositeConfiguration>
+          <compositeBuild compositeDefinitionSource="SCRIPT" />
+        </compositeConfiguration>
         <option name="distributionType" value="DEFAULT_WRAPPED" />
         <option name="externalProjectPath" value="$PROJECT_DIR$" />
         <option name="modules">

+ 1 - 1
app/build.gradle

@@ -8,7 +8,7 @@ android {
         minSdkVersion 19
         targetSdkVersion 26
         versionCode 1
-        versionName "2.8"
+        versionName "2.9"
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
         android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
 

+ 3 - 3
app/src/main/java/com/wdkl/nursewatch/MyApplication.java

@@ -46,11 +46,11 @@ public class MyApplication extends Application {
         super.onCreate();
 //        IS_HAVE_SPEAK = SharedPreferencesUtil.getBooleanSp(SharedPreferencesUtil.SETTING_RONG);
 //
-//        Intent bindIntent = new Intent(MyApplication.this, APPService.class);
-//        bindService(bindIntent, connection, BIND_AUTO_CREATE);
+        Intent bindIntent = new Intent(MyApplication.this, APPService.class);
+        bindService(bindIntent, connection, BIND_AUTO_CREATE);
 
         IS_HAVE_SPEAK = SharedPreferencesUtil.getBooleanSp(SharedPreferencesUtil.SETTING_VOICE_BROADCAST);
-        WebsocketUtil.connectWS();
+//        WebsocketUtil.connectWS();
 
         setAlarm();
     }

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

@@ -119,8 +119,8 @@ public class HomeActivity extends BaseActivity implements View.OnClickListener {
         ll_home_all.setOnClickListener(this);
             battery_view.setVisibility(View.VISIBLE);
             tv_home_network_power.setVisibility(View.VISIBLE);
-            checkBT();
-            checkLocation();
+//            checkBT();
+//            checkLocation();
 
 
         tv_home_version.setOnLongClickListener(new View.OnLongClickListener() {//这里是有的腕表连不上USB,检测用的
@@ -266,12 +266,12 @@ public class HomeActivity extends BaseActivity implements View.OnClickListener {
             }
 
             //启动蓝牙信标扫描服务
-            final Intent intent = new Intent(this, BeaconService.class);
-            intent.putExtra(BeaconService.SERVER_ID_KEY, serverId);
-            intent.putExtra(BeaconService.DEPARTMENTS_ID_KEY, departmentsId);
-            intent.putExtra(BeaconService.NURSE_ID_KEY, nurseID);
-            intent.putExtra(BeaconService.NURSE_NAME_KEY, nurseName);
-            startService(intent);
+//            final Intent intent = new Intent(this, BeaconService.class);
+//            intent.putExtra(BeaconService.SERVER_ID_KEY, serverId);
+//            intent.putExtra(BeaconService.DEPARTMENTS_ID_KEY, departmentsId);
+//            intent.putExtra(BeaconService.NURSE_ID_KEY, nurseID);
+//            intent.putExtra(BeaconService.NURSE_NAME_KEY, nurseName);
+//            startService(intent);
         } else {
             Constants.IS_LOGOUT = true;
         }

+ 6 - 6
app/src/main/java/com/wdkl/nursewatch/presentation/ui/activities/LoginActivity.java

@@ -204,12 +204,12 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
                         if (NetworkUtil.checkNetworkAvailable()) {
                             WebsocketUtil.getInstance().connect(serverId,departmentsId,nurseID);
                             //启动蓝牙信标扫描服务
-                            final Intent intent = new Intent(this, BeaconService.class);
-                            intent.putExtra(BeaconService.SERVER_ID_KEY, serverId);
-                            intent.putExtra(BeaconService.DEPARTMENTS_ID_KEY, departmentsId);
-                            intent.putExtra(BeaconService.NURSE_ID_KEY, nurseID);
-                            intent.putExtra(BeaconService.NURSE_NAME_KEY, nurseName);
-                            startService(intent);
+//                            final Intent intent = new Intent(this, BeaconService.class);
+//                            intent.putExtra(BeaconService.SERVER_ID_KEY, serverId);
+//                            intent.putExtra(BeaconService.DEPARTMENTS_ID_KEY, departmentsId);
+//                            intent.putExtra(BeaconService.NURSE_ID_KEY, nurseID);
+//                            intent.putExtra(BeaconService.NURSE_NAME_KEY, nurseName);
+//                            startService(intent);
                         }
                     } else {
                         ToastUtil.showToast(LoginActivity.this, "非法二维码!");

+ 9 - 9
app/src/main/java/com/wdkl/nursewatch/presentation/ui/activitiesphone/LoginActivityPhone.java

@@ -81,8 +81,8 @@ public class LoginActivityPhone extends BaseActivity implements View.OnClickList
 
     @Override
     protected void initData() {
-        applyPermission();
-        checkBT();
+//        applyPermission();
+//        checkBT();
     }
 
     /**
@@ -183,12 +183,12 @@ public class LoginActivityPhone extends BaseActivity implements View.OnClickList
                             output.setText("扫描成功,正在连接中...");
 
                             //启动蓝牙信标扫描服务
-                            final Intent intent = new Intent(this, BeaconService.class);
-                            intent.putExtra(BeaconService.SERVER_ID_KEY, serverId);
-                            intent.putExtra(BeaconService.DEPARTMENTS_ID_KEY, departmentsId);
-                            intent.putExtra(BeaconService.NURSE_ID_KEY, nurseID);
-                            intent.putExtra(BeaconService.NURSE_NAME_KEY, nurseName);
-                            startService(intent);
+//                            final Intent intent = new Intent(this, BeaconService.class);
+//                            intent.putExtra(BeaconService.SERVER_ID_KEY, serverId);
+//                            intent.putExtra(BeaconService.DEPARTMENTS_ID_KEY, departmentsId);
+//                            intent.putExtra(BeaconService.NURSE_ID_KEY, nurseID);
+//                            intent.putExtra(BeaconService.NURSE_NAME_KEY, nurseName);
+//                            startService(intent);
                         }
                     } else {
                         ToastUtil.showToast(LoginActivityPhone.this, "非法二维码!");
@@ -196,7 +196,7 @@ public class LoginActivityPhone extends BaseActivity implements View.OnClickList
                     }
                 } catch (Exception e) {
                     LogUtil.d("ZXResult", "扫描结果为:Exception");
-                    output.setText("扫描结果为:Exception");
+                    output.setText("扫描结果为:Exception"+e.getMessage());
                 }
             }
         }

+ 6 - 6
app/src/main/java/com/wdkl/nursewatch/presentation/ui/activitiesphone/MainActivityPhone.java

@@ -110,12 +110,12 @@ public class MainActivityPhone extends BaseActivity implements View.OnClickListe
             WebsocketUtil.connectWS();
         }
         //启动蓝牙信标扫描服务
-        final Intent intent = new Intent(this, BeaconService.class);
-        intent.putExtra(BeaconService.SERVER_ID_KEY, serverId);
-        intent.putExtra(BeaconService.DEPARTMENTS_ID_KEY, departmentsId);
-        intent.putExtra(BeaconService.NURSE_ID_KEY, nurseID);
-        intent.putExtra(BeaconService.NURSE_NAME_KEY, nurseName);
-        startService(intent);
+//        final Intent intent = new Intent(this, BeaconService.class);
+//        intent.putExtra(BeaconService.SERVER_ID_KEY, serverId);
+//        intent.putExtra(BeaconService.DEPARTMENTS_ID_KEY, departmentsId);
+//        intent.putExtra(BeaconService.NURSE_ID_KEY, nurseID);
+//        intent.putExtra(BeaconService.NURSE_NAME_KEY, nurseName);
+//        startService(intent);
 
     }
 

+ 5 - 5
app/src/main/java/com/wdkl/nursewatch/service/APPService.java

@@ -23,8 +23,8 @@ public class APPService extends Service {
 
     public void onCreate() {
         super.onCreate();
-//        checkStatus();
-//        connectWebsocket();
+        checkStatus();
+        connectWebsocket();
     }
 
     @Override
@@ -51,9 +51,9 @@ public class APPService extends Service {
             public void run() {
                 try {
                     String loginMachineId = SharedPreferencesUtil.getStringSp(SharedPreferencesUtil.LOGIN_DEPARTMENTSID);
-                    String message = "{\"type\":\"pong\",\"MachineID\":" + "\"" + loginMachineId + "\"" + ",\"DeviceType\":\"2\"}";
-                    LogUtil.d(TAG, "message==" + message);
-                    WebsocketUtil.getInstance().getWebSocket().send(message);
+//                    String message = "{\"type\":\"pong\",\"MachineID\":" + "\"" + loginMachineId + "\"" + ",\"DeviceType\":\"2\"}";
+//                    LogUtil.d(TAG, "message==" + message);
+                    WebsocketUtil.getInstance().getWebSocket().send("0");
                     LogUtil.d(TAG, "1_send_ok");
                 } catch (Exception e) {
                     LogUtil.d(TAG, "WebSocket Send Message Was Exception");

+ 39 - 0
app/src/main/java/com/wdkl/nursewatch/utils/Utils.java

@@ -0,0 +1,39 @@
+package com.wdkl.nursewatch.utils;
+
+import android.annotation.SuppressLint;
+import android.app.KeyguardManager;
+import android.content.Context;
+import android.os.PowerManager;
+
+import com.wdkl.nursewatch.MyApplication;
+
+import static android.content.Context.KEYGUARD_SERVICE;
+
+public class Utils {
+
+    public static void wakeUpAndUnlock( Context context){
+        // 获取电源管理器对象
+        PowerManager pm = (PowerManager) MyApplication.getAppContext()
+                .getSystemService(Context.POWER_SERVICE);
+        boolean screenOn = pm.isScreenOn();
+        if (!screenOn) {
+            // 获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag
+            @SuppressLint("InvalidWakeLockTag")
+            PowerManager.WakeLock wakeLock = pm.newWakeLock(
+                    PowerManager.ACQUIRE_CAUSES_WAKEUP |
+                            PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
+              wakeLock.acquire();//亮屏
+
+//            wakeLock.acquire(10000); // 点亮屏幕
+//            wakeLock.release(); // 释放
+        }
+        // 屏幕解锁
+//        KeyguardManager keyguardManager = (KeyguardManager) MyApplication.getContext()
+//                .getSystemService(KEYGUARD_SERVICE);
+//        KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("unLock");
+//        // 屏幕锁定
+//        keyguardLock.reenableKeyguard();
+//        keyguardLock.disableKeyguard(); // 解锁
+    }
+
+}

+ 10 - 6
app/src/main/java/com/wdkl/nursewatch/utils/WebsocketUtil.java

@@ -34,13 +34,13 @@ import static com.wdkl.nursewatch.presentation.ui.activitiesphone.SettingActivit
 
 public class WebsocketUtil {
     private String TAG = WebsocketUtil.class.getSimpleName();
-    //原有的
-//    public static String serverUrl = "ws://id.wdklian.com:10011/call";
+    //
+    public static String serverUrl = "ws://8.129.220.143:10011/ch/2/";
 
     //后面修改的
-//    public static String serverUrl = "ws://192.168.1.128:10011/ch/2/";
+//    public static String serverUrl = "ws://192.168.1.133:10011/ch/2/";
 
-    public static String serverUrl = "ws://39.108.248.223:10011/ch/2/";
+//    public static String serverUrl = "ws://39.108.248.223:10011/ch/2/";
 
     public static int WEBSOCKET_SUCCESS = 0;      //连接成功
     public static int WEBSOCKET_ONOPEN = 1;      //通道开放
@@ -275,8 +275,12 @@ public class WebsocketUtil {
     }
 
     public static void connectWS() {
-        if (!NetworkUtil.checkNetworkAvailable(MyApplication.getAppContext())) return;//网络不可用
-
+        //网络不可用
+        if (!NetworkUtil.checkNetworkAvailable(MyApplication.getAppContext())){
+            //需要亮屏联网
+            Utils.wakeUpAndUnlock(MyApplication.getAppContext());
+            return;
+        }
         String serverId = SharedPreferencesUtil.getStringSp(SharedPreferencesUtil.LOGIN_SERVERID);
         String loginMachineId = SharedPreferencesUtil.getStringSp(SharedPreferencesUtil.LOGIN_DEPARTMENTSID);
         String nurseId = SharedPreferencesUtil.getStringSp(SharedPreferencesUtil.LOGIN_NURSE_ID);