commit 971c2e0e8a203ab61df5d128bffceddd0c502581 Author: Your Name Date: Mon Aug 16 22:17:40 2021 +0800 提交文件 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5161fd6 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/../../../:\connect1\.idea/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..919ce1f --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..50bab57 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..22d6c08 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,14 @@ + + + + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://localhost:3306 + + + + + + \ No newline at end of file diff --git a/.idea/dataSources/bef36bc3-d0c8-41db-903b-eb43602f7eaa.xml b/.idea/dataSources/bef36bc3-d0c8-41db-903b-eb43602f7eaa.xml new file mode 100644 index 0000000..534ace8 --- /dev/null +++ b/.idea/dataSources/bef36bc3-d0c8-41db-903b-eb43602f7eaa.xml @@ -0,0 +1,946 @@ + + + + + 8.0.23 + InnoDB + InnoDB + lower/lower + + + 1 + utf8_bin + + + utf8_general_ci + + + utf8_general_ci + + + utf8mb4_0900_ai_ci + + + utf8mb4_0900_ai_ci + + + utf8mb4_0900_ai_ci + + + utf8mb4_0900_ai_ci + + + armscii8 + + + armscii8 + 1 + + + ascii + + + ascii + 1 + + + big5 + + + big5 + 1 + + + binary + 1 + + + cp1250 + + + cp1250 + + + cp1250 + + + cp1250 + 1 + + + cp1250 + + + cp1251 + + + cp1251 + + + cp1251 + 1 + + + cp1251 + + + cp1251 + + + cp1256 + + + cp1256 + 1 + + + cp1257 + + + cp1257 + 1 + + + cp1257 + + + cp850 + + + cp850 + 1 + + + cp852 + + + cp852 + 1 + + + cp866 + + + cp866 + 1 + + + cp932 + + + cp932 + 1 + + + dec8 + + + dec8 + 1 + + + eucjpms + + + eucjpms + 1 + + + euckr + + + euckr + 1 + + + gb18030 + + + gb18030 + 1 + + + gb18030 + + + gb2312 + + + gb2312 + 1 + + + gbk + + + gbk + 1 + + + geostd8 + + + geostd8 + 1 + + + greek + + + greek + 1 + + + hebrew + + + hebrew + 1 + + + hp8 + + + hp8 + 1 + + + keybcs2 + + + keybcs2 + 1 + + + koi8r + + + koi8r + 1 + + + koi8u + + + koi8u + 1 + + + latin1 + + + latin1 + + + latin1 + + + latin1 + + + latin1 + + + latin1 + + + latin1 + + + latin1 + 1 + + + latin2 + + + latin2 + + + latin2 + + + latin2 + 1 + + + latin2 + + + latin5 + + + latin5 + 1 + + + latin7 + + + latin7 + + + latin7 + 1 + + + latin7 + + + macce + + + macce + 1 + + + macroman + + + macroman + 1 + + + sjis + + + sjis + 1 + + + swe7 + + + swe7 + 1 + + + tis620 + + + tis620 + 1 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + 1 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ujis + + + ujis + 1 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + 1 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16le + + + utf16le + 1 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + 1 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + 1 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8 + + + utf8mb4 + 1 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + localhost + SELECT +SYSTEM_USER + + + + localhost + SHUTDOWN,SUPER +BACKUP_ADMIN,CLONE_ADMIN,CONNECTION_ADMIN,PERSIST_RO_VARIABLES_ADMIN,SESSION_VARIABLES_ADMIN,SYSTEM_USER,SYSTEM_VARIABLES_ADMIN +SELECT|performance_schema:null +SELECT|mysql.user:null + + + + localhost + SYSTEM_USER +TRIGGER|sys:null +SELECT|sys.sys_config:null + + + + localhost + SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,RELOAD,SHUTDOWN,PROCESS,FILE,REFERENCES,INDEX,ALTER,SHOW DATABASES,SUPER,CREATE TEMPORARY TABLES,LOCK TABLES,EXECUTE,REPLICATION SLAVE,REPLICATION CLIENT,CREATE VIEW,SHOW VIEW,CREATE ROUTINE,ALTER ROUTINE,CREATE USER,EVENT,TRIGGER,CREATE TABLESPACE,CREATE ROLE,DROP ROLE! + + + + 版本号 + utf8_general_ci +
+ + 1 + int|0s + 1 + null + + + 2 + varchar(20)|0s + 1 + + + 3 + varchar(45)|0s + 1 + + + 4 + varchar(45)|0s + 1 + + + 1 + id + 1 + +
+
\ No newline at end of file diff --git a/.idea/dataSources/bef36bc3-d0c8-41db-903b-eb43602f7eaa/storage_v2/_src_/schema/information_schema.FNRwLQ.meta b/.idea/dataSources/bef36bc3-d0c8-41db-903b-eb43602f7eaa/storage_v2/_src_/schema/information_schema.FNRwLQ.meta new file mode 100644 index 0000000..1ff3db2 --- /dev/null +++ b/.idea/dataSources/bef36bc3-d0c8-41db-903b-eb43602f7eaa/storage_v2/_src_/schema/information_schema.FNRwLQ.meta @@ -0,0 +1,2 @@ +#n:information_schema +! [null, 0, null, null, -2147483648, -2147483648] diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..4987eca --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4b661a5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/connect1.iml b/connect1.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/connect1.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ec16d73 --- /dev/null +++ b/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + org.example + connect1 + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 7 + 7 + + + + + + + + mysql + mysql-connector-java + 8.0.20 + + + + com.google.android + android + 4.1.1.4 + provided + + + + + + + \ No newline at end of file diff --git a/src/main/java/Interface/addVersionInterface.java b/src/main/java/Interface/addVersionInterface.java new file mode 100644 index 0000000..263f8b1 --- /dev/null +++ b/src/main/java/Interface/addVersionInterface.java @@ -0,0 +1,6 @@ +package Interface; + +public interface addVersionInterface { + //更新接口 + public void fresh(String VersionId, String apkUrl, String updateDescription); +} diff --git a/src/main/java/Interface/refreshInterFace.java b/src/main/java/Interface/refreshInterFace.java new file mode 100644 index 0000000..2dc635a --- /dev/null +++ b/src/main/java/Interface/refreshInterFace.java @@ -0,0 +1,7 @@ +package Interface; + +public interface refreshInterFace { + + //判断是否需要更新,比对是否有新的版本 + public boolean new_version() throws Exception; +} diff --git a/src/main/java/Service/add.java b/src/main/java/Service/add.java new file mode 100644 index 0000000..d9c0ded --- /dev/null +++ b/src/main/java/Service/add.java @@ -0,0 +1,12 @@ +package Service; + +import Interface.addVersionInterface; +import dao.dataDao; + +public class add implements addVersionInterface { + @Override + public void fresh(String VersionId, String apkUrl, String updateDescription) { + dataDao.add(VersionId, apkUrl, updateDescription); + } + +} diff --git a/src/main/java/Service/refresh.java b/src/main/java/Service/refresh.java new file mode 100644 index 0000000..6326c53 --- /dev/null +++ b/src/main/java/Service/refresh.java @@ -0,0 +1,42 @@ +package Service; + +import Interface.refreshInterFace; +import android.app.Application; +import android.content.Context; +import dao.dataDao; +import util.APKVersionCodeUtils; + +public class refresh implements refreshInterFace { + //version1大返回一个正数,小返回一个负数,相等返回0 + public static int compareVersion(String version1, String version2) throws Exception { + if (version1 == null || version2 == null) { + throw new Exception("compareVersion error:illegal params."); + } + String[] versionArray1 = version1.split("\\."); + String[] versionArray2 = version2.split("\\."); + int idx = 0; + int minLength = Math.min(versionArray1.length, versionArray2.length); + int diff = 0; + while (idx < minLength + && (diff = versionArray1[idx].length() - versionArray2[idx].length()) == 0 + && (diff = versionArray1[idx].compareTo(versionArray2[idx])) == 0) { + ++idx; + } + //如果已经分出大小,则直接返回,如果未分出大小,则再比较位数,有子版本的为大; + diff = (diff != 0) ? diff : versionArray1.length - versionArray2.length; + return diff; + } + + Application application = new Application(); + Context ass = application.getApplicationContext(); + String oldVersion = APKVersionCodeUtils.getVerName(ass); + String newVersion = dataDao.getNewVersion(); + + @Override + public boolean new_version() throws Exception { + if (compareVersion(oldVersion, newVersion) < 0){ + return true; + } + return false; + } +} diff --git a/src/main/java/dao/dataDao.java b/src/main/java/dao/dataDao.java new file mode 100644 index 0000000..60c9eb9 --- /dev/null +++ b/src/main/java/dao/dataDao.java @@ -0,0 +1,51 @@ +package dao; + +import util.MysqlDriver; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class dataDao { + public static void add(String VersionId, String apkUrl, String updateDescription) { + Connection connection = MysqlDriver.getConnection(); + String sql = "INSERT INTO `fresh` (`VersionId`,`apkUrl`,`updateDescription` ) VALUES(?,?,?)"; + PreparedStatement preparedStatement = null; + try { + preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, VersionId); + preparedStatement.setString(2, apkUrl); + preparedStatement.setString(3, updateDescription); + preparedStatement.execute(); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + MysqlDriver.close(preparedStatement); + MysqlDriver.close(connection); + } + } + public static String getNewVersion(){ + Connection connection = MysqlDriver.getConnection(); + String sql = "SELECT VersionId FROM fresh ORDER BY id DESC LIMIT 1"; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + String version = null; + try { + preparedStatement = connection.prepareStatement(sql); + resultSet = preparedStatement.executeQuery(); + + if (resultSet.next()) { + version = resultSet.getString("VersionId"); + } + } catch (SQLException e) { + e.printStackTrace(); + } finally { + MysqlDriver.close(resultSet); + MysqlDriver.close(preparedStatement); + MysqlDriver.close(connection); + } + return version; + } +} + diff --git a/src/main/java/util/APKVersionCodeUtils.java b/src/main/java/util/APKVersionCodeUtils.java new file mode 100644 index 0000000..54515ff --- /dev/null +++ b/src/main/java/util/APKVersionCodeUtils.java @@ -0,0 +1,28 @@ +package util; + +import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; + + +public class APKVersionCodeUtils { + + /** + * 获取版本号名称 + * + * @param context 上下文 + * @return + */ + public static String getVerName(Context context) { + String verName = ""; + try { + verName = context.getPackageManager(). + getPackageInfo(context.getPackageName(), 0).versionName; + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + return verName; + } + +} + diff --git a/src/main/java/util/MysqlDriver.java b/src/main/java/util/MysqlDriver.java new file mode 100644 index 0000000..0c4476c --- /dev/null +++ b/src/main/java/util/MysqlDriver.java @@ -0,0 +1,46 @@ +package util; + +import java.sql.*; + +public class MysqlDriver { + public static Connection getConnection() { + Connection connection = null; + try { + Class.forName("com.mysql.cj.jdbc.Driver"); + connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + "emoji" + "?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false", "root", "root"); + } catch (ClassNotFoundException | SQLException e) { + e.printStackTrace(); + } + return connection; + } + + public static void close(Connection connection) { + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + public static void close(PreparedStatement preparedStatement) { + if (preparedStatement != null) { + try { + preparedStatement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + public static void close(ResultSet resultSet) { + if (resultSet != null) { + try { + resultSet.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } +} diff --git a/target/classes/Interface/addVersionInterface.class b/target/classes/Interface/addVersionInterface.class new file mode 100644 index 0000000..d4568c3 Binary files /dev/null and b/target/classes/Interface/addVersionInterface.class differ diff --git a/target/classes/Interface/refreshInterFace.class b/target/classes/Interface/refreshInterFace.class new file mode 100644 index 0000000..db9c33c Binary files /dev/null and b/target/classes/Interface/refreshInterFace.class differ diff --git a/target/classes/Service/add.class b/target/classes/Service/add.class new file mode 100644 index 0000000..609c584 Binary files /dev/null and b/target/classes/Service/add.class differ diff --git a/target/classes/Service/refresh.class b/target/classes/Service/refresh.class new file mode 100644 index 0000000..e377116 Binary files /dev/null and b/target/classes/Service/refresh.class differ diff --git a/target/classes/dao/dataDao.class b/target/classes/dao/dataDao.class new file mode 100644 index 0000000..9ee304c Binary files /dev/null and b/target/classes/dao/dataDao.class differ diff --git a/target/classes/util/APKVersionCodeUtils.class b/target/classes/util/APKVersionCodeUtils.class new file mode 100644 index 0000000..f097729 Binary files /dev/null and b/target/classes/util/APKVersionCodeUtils.class differ diff --git a/target/classes/util/MysqlDriver.class b/target/classes/util/MysqlDriver.class new file mode 100644 index 0000000..cb3714c Binary files /dev/null and b/target/classes/util/MysqlDriver.class differ