diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 35e586f..b9780c2 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -26,17 +26,45 @@
tools:targetApi="31">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/tenlionsoft/xzdisplay/BaseMyApplication.java b/app/src/main/java/com/tenlionsoft/xzdisplay/BaseMyApplication.java
index 307134f..225fd3c 100644
--- a/app/src/main/java/com/tenlionsoft/xzdisplay/BaseMyApplication.java
+++ b/app/src/main/java/com/tenlionsoft/xzdisplay/BaseMyApplication.java
@@ -1,13 +1,35 @@
package com.tenlionsoft.xzdisplay;
import android.app.Application;
+import android.content.Intent;
+import android.os.Process;
import com.hjq.toast.ToastUtils;
public class BaseMyApplication extends Application {
+ private final Thread.UncaughtExceptionHandler restartHandler = BaseMyApplication.this::lambda$new$2$BaseMyApplication;
+
@Override
public void onCreate() {
super.onCreate();
ToastUtils.init(this);
+ Thread.setDefaultUncaughtExceptionHandler(this.restartHandler);
+ }
+
+ public /* synthetic */ void lambda$new$2$BaseMyApplication(Thread thread, Throwable th) {
+ try {
+ th.printStackTrace();
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ restartApp();
+ }
+
+ public void restartApp() {
+ Intent intent = new Intent(this, MainActivity.class);
+ intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
+ startActivity(intent);
+ Process.killProcess(Process.myPid());
}
}
diff --git a/app/src/main/java/com/tenlionsoft/xzdisplay/MainActivity.java b/app/src/main/java/com/tenlionsoft/xzdisplay/MainActivity.java
index fc1698b..54aa052 100644
--- a/app/src/main/java/com/tenlionsoft/xzdisplay/MainActivity.java
+++ b/app/src/main/java/com/tenlionsoft/xzdisplay/MainActivity.java
@@ -40,6 +40,7 @@ import com.tenlionsoft.baselib.core.retrofit_net.api.BaseApiService;
import com.tenlionsoft.baselib.core.retrofit_net.bean.VersionBean;
import com.tenlionsoft.baselib.core.widget.views.BottomSettingPwdView;
import com.tenlionsoft.baselib.core.widget.views.BottomSettingView;
+import com.tenlionsoft.baselib.utils.AppUtils;
import com.tenlionsoft.baselib.utils.ExceptionHandler;
import com.tenlionsoft.baselib.utils.LogUtils;
import com.tenlionsoft.baselib.utils.ProiderUtil;
@@ -50,6 +51,7 @@ import com.tenlionsoft.xzdisplay.beans.PlaceListBean;
import com.tenlionsoft.xzdisplay.beans.ShowDataBean;
import com.tenlionsoft.xzdisplay.beans.WebBottomTabDataBean;
import com.tenlionsoft.xzdisplay.net.ApiDisplay;
+import com.tenlionsoft.xzdisplay.push.ServerClient;
import com.tenlionsoft.xzdisplay.widget.CustomWebView;
import java.io.DataOutputStream;
@@ -336,10 +338,20 @@ public class MainActivity extends Activity {
});
}
+ @Override
+ protected void onStart() {
+ super.onStart();
+ if (!AppUtils.serviceIsRunning()) {
+ LogUtils.e("server打开");
+ ServerClient.start(getApplicationContext());
+ }
+ }
+
private void startDownloadApk() {
ToastUtils.show("开始下载");
Intent intent = new Intent((Context) this, DownloadService.class);
- intent.putExtra("downloadUrl", "http://192.168.1.100:7001/usercenter/app/appversion/downloadapp/e2f64ae0-69a5-454c-8471" +
+ intent.putExtra("downloadUrl", "http://192.168.1.100:7001/usercenter/app/appversion/downloadapp/e2f64ae0-69a5" +
+ "-454c-8471" +
"-483291a7bfb1");
startService(intent);
}
diff --git a/app/src/main/java/com/tenlionsoft/xzdisplay/beans/ConfigBean.java b/app/src/main/java/com/tenlionsoft/xzdisplay/beans/ConfigBean.java
new file mode 100644
index 0000000..538f735
--- /dev/null
+++ b/app/src/main/java/com/tenlionsoft/xzdisplay/beans/ConfigBean.java
@@ -0,0 +1,85 @@
+package com.tenlionsoft.xzdisplay.beans;
+
+public class ConfigBean {
+ private String baseUrl;
+ private String deviceCode;
+ private String deviceIp;
+ private String height;
+ private boolean playSound;
+ private String pwd;
+ private String resolution;
+ private String screenDirection;
+ private String width;
+
+ public String getPwd() {
+ return this.pwd;
+ }
+
+ public void setPwd(String str) {
+ this.pwd = str;
+ }
+
+ public String getBaseUrl() {
+ return this.baseUrl;
+ }
+
+ public void setBaseUrl(String str) {
+ this.baseUrl = str;
+ }
+
+ public String getDeviceCode() {
+ return this.deviceCode;
+ }
+
+ public void setDeviceCode(String str) {
+ this.deviceCode = str;
+ }
+
+ public String getDeviceIp() {
+ return this.deviceIp;
+ }
+
+ public void setDeviceIp(String str) {
+ this.deviceIp = str;
+ }
+
+ public boolean isPlaySound() {
+ return this.playSound;
+ }
+
+ public void setPlaySound(boolean z) {
+ this.playSound = z;
+ }
+
+ public String getScreenDirection() {
+ return this.screenDirection;
+ }
+
+ public void setScreenDirection(String str) {
+ this.screenDirection = str;
+ }
+
+ public String getWidth() {
+ return this.width;
+ }
+
+ public void setWidth(String str) {
+ this.width = str;
+ }
+
+ public String getHeight() {
+ return this.height;
+ }
+
+ public void setHeight(String str) {
+ this.height = str;
+ }
+
+ public String getResolution() {
+ return this.resolution;
+ }
+
+ public void setResolution(String str) {
+ this.resolution = str;
+ }
+}
diff --git a/app/src/main/java/com/tenlionsoft/xzdisplay/push/ServerClient.java b/app/src/main/java/com/tenlionsoft/xzdisplay/push/ServerClient.java
index 4869fea..622d2dc 100755
--- a/app/src/main/java/com/tenlionsoft/xzdisplay/push/ServerClient.java
+++ b/app/src/main/java/com/tenlionsoft/xzdisplay/push/ServerClient.java
@@ -11,15 +11,19 @@ import android.os.Build;
import android.os.IBinder;
import android.text.TextUtils;
+import com.google.gson.Gson;
import com.koushikdutta.async.AsyncServer;
import com.koushikdutta.async.http.Multimap;
import com.koushikdutta.async.http.server.AsyncHttpServer;
import com.koushikdutta.async.http.server.AsyncHttpServerRequest;
import com.koushikdutta.async.http.server.AsyncHttpServerResponse;
import com.tenlionsoft.baselib.constant.PathConfig;
+import com.tenlionsoft.baselib.core.retrofit_net.BaseUrlApi;
import com.tenlionsoft.baselib.utils.LogUtils;
+import com.tenlionsoft.baselib.utils.NetworkUtils;
import com.tenlionsoft.baselib.utils.SPUtils;
import com.tenlionsoft.xzdisplay.R;
+import com.tenlionsoft.xzdisplay.beans.ConfigBean;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -85,25 +89,6 @@ public class ServerClient extends Service {
}
return super.onStartCommand(intent, flags, startId);
}
-// public static Notification buildNotification(Context paramContext) {
-// Notification notification;
-// if (Build.VERSION.SDK_INT >= 26) {
-// NotificationChannel notificationChannel = new NotificationChannel("default", "展览系统", 3);
-// notificationChannel.setLightColor(-16711936);
-// notificationChannel.setLockscreenVisibility(0);
-// getNotificationManager(paramContext).createNotificationChannel(notificationChannel);
-// notification = (new Notification.Builder(paramContext, "default")).setContentTitle(").setContentText(")
-// .setSmallIcon(2131230818).setAutoCancel(true).build();
-// } else {
-// Notification.Builder builder = new Notification.Builder((Context)notification);
-// builder.setSmallIcon(2131230818);
-// builder.setContentTitle(");
-// builder.setContentText(").setWhen(System.currentTimeMillis());
-// notification = builder.build();
-// LogUtils.e(new Object[] { "});
-// }
-// return notification;
-// }
public static Notification buildNotification(Context context) {
@@ -166,149 +151,35 @@ public class ServerClient extends Service {
response.code(500).end();
}
});
-// server.get("/ximengjianyu/getAppVersion", (request, response) -> {
-// try {
-// Multimap query = request.getQuery();
-// String url = query.getString("url");
-// String versioncode = query.getString("versioncode");
-// String md5 = query.getString("md5");
-// fileUploadHolder.setAppVersion(url, versioncode, md5);
-// fileUploadHolder.reset();
-// Intent intent = new Intent();
-// intent.setAction(Constants.ACTION_PUSH_APP_INSTALL);
-// sendBroadcast(intent);
-// response.code(200);
-// response.send("成功");
-// } catch (Exception e) {
-// e.printStackTrace();
-// response.code(500);
-// response.send("服务器错误");
-// }
-// });
-// server.get("/cqjianqyu/getAppVersion", (request, response) -> {
-// AsyncHttpRequestBody body = request.getBody();
-// });
-// /**
-// * 推送设置
-// */
-// server.get("/ximengjianyu/setAppConfig", (request, response) -> {
-// try {
-// Multimap query = request.getQuery();
-// String baseUrl = query.getString("baseUrl");//项目地址
-// String title = new String(query.getString("title").getBytes(), "UTF-8");
-// String spSec = query.getString("spSec");//延迟时间
-// String settingPwd = query.getString("settingPwd");//设置密码
-// String cmVersion = query.getString("cmVersion");//项目版本
-// String loginType = query.getString("loginType");//登录方式
-// String useType = query.getString("useType");
-// String faceRate = query.getString("faceRate");//识别码率
-// String count = query.getString("count");//限制跳转登录次数
-// if (!TextUtils.isEmpty(count)) {
-// PrefUtils.putInt(MyApplication.getInstance(), Constants.COUNT, Integer.parseInt(count));
-// MyApplication.getInstance().mConfigCount = Integer.parseInt(count);
-// }
-// if (!TextUtils.isEmpty(faceRate)) {
-// PrefUtils.putString(MyApplication.getInstance(), Constants.FACE_RATE, faceRate);
-// MyApplication.getInstance().mFaceRate = Float.parseFloat(faceRate);
-// }
-// if (!TextUtils.isEmpty(useType)) {
-// PrefUtils.putString(MyApplication.getInstance(), Constants.USE_TYPE, useType);
-// MyApplication.getInstance().mUseType = useType;
-// }
-// if (!TextUtils.isEmpty(baseUrl)) {
-// PrefUtils.putString(MyApplication.getInstance(), Constants.BASE_IP, baseUrl);
-// MyApplication.getInstance().base_ip = baseUrl;
-// }
-// if (!TextUtils.isEmpty(title)) {
-// PrefUtils.putString(MyApplication.getInstance(), Constants.PRISON_NAME, title);
-// MyApplication.getInstance().mPrisonName = title;
-// }
-// if (!TextUtils.isEmpty(spSec)) {
-// PrefUtils.putInt(MyApplication.getInstance(), Constants.SP_SEC, Integer.parseInt(spSec));
-// MyApplication.getInstance().mSpSec = Integer.parseInt(spSec);
-// }
-// if (!TextUtils.isEmpty(settingPwd)) {
-// PrefUtils.putString(MyApplication.getInstance(), Constants.SETTING_PWD, settingPwd);
-// MyApplication.getInstance().mSettingPwd = settingPwd;
-// }
-// if (!TextUtils.isEmpty(cmVersion)) {
-// PrefUtils.putString(MyApplication.getInstance(), Constants.CM_VERSION, cmVersion);
-// MyApplication.getInstance().mCmVersion = cmVersion;
-// }
-// if (!TextUtils.isEmpty(loginType)) {
-// PrefUtils.putString(MyApplication.getInstance(), Constants.LOGINTYPE, loginType);
-// MyApplication.getInstance().mLoginType = loginType;
-// }
-// response.code(200);
-// response.send("成功");
-// } catch (Exception e) {
-// e.printStackTrace();
-// response.code(500);
-// response.send("服务器错误");
-// }
-// });
-// /**
-// * 推送设置
-// */
-// server.get("/ximengjianyu/getAppConfigInfo", (request, response) -> {
-// try {
-// ConfigBean bean = new ConfigBean();
-// bean.setBaseUrl(MyApplication.getInstance().base_ip);
-// bean.setTitle(MyApplication.getInstance().mPrisonName);
-// bean.setSpSec(MyApplication.getInstance().mSpSec + "");
-// bean.setCmVersion(MyApplication.getInstance().mCmVersion);
-// bean.setLoginType(MyApplication.getInstance().mLoginType);
-// bean.setSettingPwd(MyApplication.getInstance().mSettingPwd);
-// bean.setUseType(MyApplication.getInstance().mUseType);
-// bean.setAppVersionName(AppUtils.getAppVersionName());
-// bean.setAppVersionCode(AppUtils.getAppVersionCode() + "");
-// bean.setFaceRate(MyApplication.getInstance().mFaceRate + "");
-// Gson gson = new Gson();
-// String res = gson.toJson(bean);
-// response.code(200);
-// response.send(res);
-// } catch (Exception e) {
-// e.printStackTrace();
-// response.code(500);
-// response.send("服务器错误");
-// }
-// });
-//
-//
-//
-// /**
-// * 获取App版本以及appKey
-// */
-// server.get("/ximengjianyu/getAppConfigInfo", (request, response) -> {
-// try {
-//// AppUtils.AppInfo info = AppUtils.getAppInfo();
-//// int versionCode = info.getVersionCode();
-//// String versionName = info.getVersionName();
-//// String appKey = getApplication().getString(R.string.appKey);
-//// String sInfo = "versionCode=" + versionCode + ",versionName=" + versionName + ",appKey=" + appKey;
-// response.code(200);
-// response.send(sInfo);
-// } catch (Exception e) {
-// e.printStackTrace();
-// response.code(500);
-// response.send("服务器错误");
-// }
-//
-// });
-
-
this.server.get("/onlineStatus", this::getOnlineStatus);
this.server.get("/updateShow", this::doUpdateShow);
this.server.get("/shutDown", this::doShutDown);
this.server.get("/appUpdate", this::doUpdateApp);
this.server.get("/setAppConfig", this::setAppConfig);
- this.server.get("/getAppConfigInfo", this::getAppconfigInfo);
+ this.server.get("/getAppConfigInfo", this::getAppConfigInfo);
server.listen(mAsyncServer, 12345);
+ LogUtils.e("开始监听");
}
- private void getAppconfigInfo(AsyncHttpServerRequest asyncHttpServerRequest,
+ private void getAppConfigInfo(AsyncHttpServerRequest asyncHttpServerRequest,
AsyncHttpServerResponse asyncHttpServerResponse) {
-
+ try {
+ ConfigBean configBean = new ConfigBean();
+ configBean.setBaseUrl(SPUtils.getInstance().getString("baseUrl"));
+ configBean.setDeviceCode(SPUtils.getInstance().getString("deviceCode"));
+ configBean.setDeviceIp(NetworkUtils.getIPAddress(true));
+ configBean.setScreenDirection(SPUtils.getInstance().getString("appType"));
+ configBean.setPlaySound(SPUtils.getInstance().getBoolean("playSound"));
+ configBean.setPwd(TextUtils.isEmpty(SPUtils.getInstance().getString("pwd")) ? BaseUrlApi.SETTING_PWD :
+ SPUtils.getInstance().getString("pwd"));
+ String json = new Gson().toJson((Object) configBean);
+ asyncHttpServerResponse.code(200);
+ asyncHttpServerResponse.send(json);
+ } catch (Exception e) {
+ e.printStackTrace();
+ asyncHttpServerResponse.code(500);
+ asyncHttpServerResponse.send("服务器错误");
+ }
}
private void setAppConfig(AsyncHttpServerRequest asyncHttpServerRequest,
@@ -401,7 +272,14 @@ public class ServerClient extends Service {
* 获取设备状态
*/
private void getOnlineStatus(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
-
+ try {
+ response.code(200);
+ response.send("成功");
+ } catch (Exception e) {
+ e.printStackTrace();
+ response.code(500);
+ response.send("服务器错误");
+ }
}
/**
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index df40e88..1208063 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,5 +1,6 @@
@@ -18,18 +19,19 @@
android:orientation="vertical">
-
+
\ No newline at end of file
diff --git a/baselib/src/main/java/com/tenlionsoft/baselib/utils/AppUtils.java b/baselib/src/main/java/com/tenlionsoft/baselib/utils/AppUtils.java
index af589c3..104748c 100755
--- a/baselib/src/main/java/com/tenlionsoft/baselib/utils/AppUtils.java
+++ b/baselib/src/main/java/com/tenlionsoft/baselib/utils/AppUtils.java
@@ -125,11 +125,11 @@ public final class AppUtils {
Iterator iterator =
((ActivityManager) Utils.getApp()
.getApplicationContext()
- .getSystemService("activity"))
+ .getSystemService(Context.ACTIVITY_SERVICE))
.getRunningServices(2147483647)
.iterator();
while (iterator.hasNext()) {
- if ("com.tengshisoft.hanging.push.ServerClient".equals(((ActivityManager.RunningServiceInfo) iterator.next()).service.getClassName()))
+ if ("com.tenlionsoft.xzdisplay.push.ServerClient".equals(((ActivityManager.RunningServiceInfo) iterator.next()).service.getClassName()))
return true;
}
return false;