Browse Source

apk更新完善

wbspool 1 year ago
parent
commit
ea7ae4d51b

+ 2 - 2
BusinessCommon/src/main/java/com/develop/common/data_repo/net/model/response/DevInfoResult.kt

@@ -42,7 +42,7 @@ data class ApkInfo(
     val productName: String?,
     val productSubModel: String?,
     val releaseStatus: String?,
-    val releaseTime: String?,
+    val releaseTime: Long?,
     val rollbackReason: String?,
     val rollbackTime: String?,
     val startTime: String?,
@@ -54,7 +54,7 @@ data class ApkInfo(
     val subBrandProductCode: String?,
     val subEdition: String?,
     val testStatus: String?,
-    val testTime: String?,
+    val testTime: Long?,
     val updateTime: Long,
     val valid: Int,
     val version: Int

+ 15 - 0
BusinessCommon/src/main/java/com/develop/common/dialog/CommonDialog.kt

@@ -4,7 +4,10 @@ import android.os.Bundle
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import androidx.fragment.app.FragmentManager
 import com.develop.base.mvvm.FullScreenTransparentDialog
+import com.develop.base.util.TopResumedAtyHolder
+import com.develop.common.R
 import com.develop.common.databinding.DialogCommonBinding
 
 
@@ -13,6 +16,9 @@ class CommonDialog(
     private lateinit var binding: DialogCommonBinding
 
     var msg = ""
+
+    var title = ""
+
     override fun onCreateView(
         inflater: LayoutInflater,
         container: ViewGroup?,
@@ -22,6 +28,7 @@ class CommonDialog(
             inflater, container, false
         )
         binding.tvMsg.text = msg
+        binding.tvFinish.text = title
         binding.tvOk.setOnClickListener {
             removeSelf()
         }
@@ -40,4 +47,12 @@ class CommonDialog(
     fun updateProgress(progress: String) {
         binding.tvProgress.text = progress
     }
+
+    fun showDialog2(manager: FragmentManager, tag: String) {
+        TopResumedAtyHolder.getCurrentActivity()?.apply {
+            msg = getString(R.string.no_recipe_update_tips)
+        }
+        showDialog(manager, tag)
+    }
+
 }

+ 178 - 1
BusinessCommon/src/main/java/com/develop/common/utils/UpdateUtil.kt

@@ -1,28 +1,205 @@
 package com.develop.common.utils
 
 import android.app.Activity
+import android.app.PendingIntent
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+import android.content.pm.PackageInstaller
+import android.net.Uri
+import android.os.Bundle
+import android.provider.Settings
+import com.azhon.appupdate.base.BaseHttpDownloadManager
+import com.azhon.appupdate.base.bean.DownloadStatus
+import com.azhon.appupdate.config.Constant
 import com.azhon.appupdate.listener.OnDownloadListener
 import com.azhon.appupdate.manager.DownloadManager
+import com.azhon.appupdate.manager.HttpDownloadManager
+import com.azhon.appupdate.util.LogUtil
 import com.develop.base.R
+import com.develop.base.util.GlobalToast
+import com.develop.base.util.TopResumedAtyHolder
+import com.develop.common.data_repo.net.Api
+import com.develop.common.data_repo.net.model.request.DeviceInfoBody
+import com.develop.common.data_repo.net.model.response.DevInfoResult
+import com.develop.common.dialog.CancelConfirmDialog
+import com.develop.common.dialog.CommonDialog
+import com.develop.common.dialog.RecipeUpdateDialog
+import com.drake.net.Post
+import com.drake.net.utils.scopeNetLife
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.flow.*
+import okhttp3.OkHttpClient
+import okhttp3.Request
+import java.io.File
+import java.io.FileOutputStream
+import java.net.HttpURLConnection
+import java.net.SocketTimeoutException
+import java.net.URL
+import java.security.SecureRandom
+import java.security.cert.X509Certificate
+import java.util.*
+import java.util.concurrent.TimeUnit
+import javax.net.ssl.HttpsURLConnection
+import javax.net.ssl.SSLContext
+import javax.net.ssl.TrustManager
+import javax.net.ssl.X509TrustManager
 
 object UpdateUtil {
 
+    fun checkApkVersion() {
+
+        TopResumedAtyHolder.getCurrentActivity()?.apply {
+            scopeNetLife {
+
+                try {
+                    val result = Post<DevInfoResult>(Api.DEV_INFO) {
+                        body = DeviceInfoBody.genDeviceInfoBody()
+                    }.await()
+                    val ctx = this@apply
+                    if (result.apkUpdate) {
+                        val commonDialog = CommonDialog()
+                        commonDialog.msg = getString(com.develop.common.R.string.update_msg)
+                        commonDialog.title = getString(com.develop.common.R.string.update)
+                        commonDialog.hasOKBtn = false
+                        val cancelConfirmDialog = CancelConfirmDialog()
+                        cancelConfirmDialog.title = getString(com.develop.common.R.string.update_title)
+                        cancelConfirmDialog.showDialog(supportFragmentManager, "commonDialog")
+                        cancelConfirmDialog.onDialogClickListener =
+                            object : CancelConfirmDialog.OnDialogClickListener {
+                                override fun onConfirm() {
+                                    commonDialog.showDialog(supportFragmentManager, "commonDialog")
+                                    updateApp(
+                                         ctx,
+                                        result.apkUrl,
+                                        object : OnDownloadListener {
+                                            override fun cancel() {
+                                                runOnUiThread {
+                                                    commonDialog.removeSelf()
+                                                }
+                                            }
+
+                                            override fun done(apk: File) {
+                                                GlobalToast.showToast(getString(com.develop.common.R.string.finish_download))
+                                                installPackage(ctx,apk)
+                                                commonDialog.updateProgress(getString(com.develop.common.R.string.installing))
+                                            }
+
+                                            override fun downloading(max: Int, progress: Int) {
+                                                runOnUiThread {
+                                                    commonDialog.updateProgress(
+                                                        "${
+                                                            String.format(
+                                                                "%.0f",
+                                                                ((progress.toFloat() / max.toFloat()) * 100f)
+                                                            )
+                                                        }%"
+                                                    )
+                                                }
+                                            }
+
+                                            override fun error(e: Throwable) {
+                                                GlobalToast.showToast(getString(com.develop.common.R.string.download_fail))
+                                                runOnUiThread {
+                                                    commonDialog.removeSelf()
+                                                }
+                                            }
+
+                                            override fun start() {
+//                                GlobalToast.showToast(getString(com.develop.common.R.string.start_download))
+                                            }
+
+                                        })
+                                }
+
+                                override fun onCancel() {
+
+                                }
+                            }
+                    }else{
+                        GlobalToast.showToast(getString(com.develop.common.R.string.apk_version_latest))
+                    }
+
+                } catch (e: java.lang.Exception) {
+                    e.printStackTrace()
+                }
+
+
+            }
+
+        }
+    }
+
     fun updateApp(
         activity: Activity,
         apkUrl: String,
         downloadListener: OnDownloadListener
     ) {
+
+
         val manager = DownloadManager.Builder(activity).run {
             apkUrl(apkUrl)
             smallIcon(com.develop.common.R.drawable.ic_icon6)
             apkName("foodCooking.apk")
+            jumpInstallPage(false)
+            forcedUpgrade(false)
             onDownloadListener(downloadListener)
+            showBgdToast(false)
             build()
         }
         manager.download()
     }
 
+    fun installPackage(context: Context, apk: File) {
+        try {
+            val packageInstaller = context.packageManager.packageInstaller
+
+            val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL)
+
+            val sessionId = packageInstaller.createSession(params)
+            val session = packageInstaller.openSession(sessionId)
+
+            addApkToSession(apk, session)
+
+            val intent = Intent(context, InstallResultReceiver::class.java)
+            val pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
+
+            session.commit(pendingIntent.intentSender)
+
+            session.close()
+        } catch (e: Exception) {
+            e.printStackTrace()
+        }
+    }
+
+    private fun addApkToSession(file: File, session: PackageInstaller.Session) {
+        file.inputStream().use { inputStream ->
+            session.openWrite("COSU", 0, -1).use { outputStream ->
+                val buffer = ByteArray(4096)
+                var length: Int
+                while (inputStream.read(buffer).also { length = it } != -1) {
+                    outputStream.write(buffer, 0, length)
+                }
+            }
+        }
+    }
+
+    class InstallResultReceiver : BroadcastReceiver() {
+        override fun onReceive(context: Context, intent: Intent) {
+            val extras: Bundle? = intent.extras
+            if (extras != null) {
+                val status = extras.getInt(PackageInstaller.EXTRA_STATUS)
+                // 处理安装结果
+                // status 是安装结果代码
+                // 可以使用PackageInstaller.Session的常量来解释结果
+
+                val message = extras.getString(PackageInstaller.EXTRA_STATUS_MESSAGE)
+                // 如果需要,可以获取附加的结果信息
+            }
+        }
+    }
+
     private fun getApkName(url: String): String {
         return url.subSequence(url.lastIndexOf("/"), url.length).toString()
     }
-}
+}

+ 10 - 9
BusinessCommon/src/main/res/layout/dialog_common.xml

@@ -7,9 +7,11 @@
     tools:background="#444">
 
     <RelativeLayout
-        android:layout_width="@dimen/convert_780px"
-        android:layout_height="@dimen/convert_720px"
+        android:layout_width="@dimen/convert_500px"
+        android:layout_height="wrap_content"
         android:layout_gravity="center"
+        android:paddingTop="@dimen/convert_81px"
+        android:paddingBottom="@dimen/convert_64px"
         android:background="@drawable/bg_icon_page">
 
         <TextView
@@ -17,17 +19,16 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_centerHorizontal="true"
-            android:layout_marginTop="@dimen/convert_78px"
             android:includeFontPadding="false"
             android:text="提示!"
             android:textColor="#E60012"
-            android:textSize="@dimen/convert_90px" />
+            android:textSize="@dimen/convert_30px" />
 
         <androidx.appcompat.widget.AppCompatTextView
             android:id="@+id/tv_msg"
             android:gravity="center"
             android:text="菜谱正在运行中~"
-            android:textSize="@dimen/convert_46px"
+            android:textSize="@dimen/convert_30px"
             android:textColor="@color/color_000000"
             android:layout_marginStart="@dimen/convert_80px"
             android:layout_marginEnd="@dimen/convert_80px"
@@ -45,12 +46,12 @@
             android:layout_height="@dimen/convert_120px"
             android:layout_below="@+id/tv_msg"
             android:layout_centerHorizontal="true"
-            android:layout_marginTop="@dimen/convert_98px"
+            android:layout_marginTop="@dimen/convert_30px"
             android:background="@drawable/bg_cook_step_ok"
             android:gravity="center"
             android:text="OK"
             android:textColor="#ffffff"
-            android:textSize="@dimen/convert_54px" />
+            android:textSize="@dimen/convert_30px" />
 
 
         <TextView
@@ -60,11 +61,11 @@
             android:layout_height="wrap_content"
             android:layout_below="@+id/tv_msg"
             android:layout_centerHorizontal="true"
-            android:layout_marginTop="@dimen/convert_98px"
+            android:layout_marginTop="@dimen/convert_30px"
             android:gravity="center"
             android:text="0%"
             android:textColor="#000000"
-            android:textSize="@dimen/convert_72px"/>
+            android:textSize="@dimen/convert_30px"/>
     </RelativeLayout>
 
 

+ 3 - 3
BusinessCommon/src/main/res/values-fr/strings.xml

@@ -83,9 +83,9 @@ Nanfang plus client is an online information platform developed and operated by
     <string name="update_the_recipes">Mise à jour des recettes</string>
     <string name="apk">APK</string>
     <string name="mcu">MCU</string>
-    <string name="tp">TP</string>
-    <string name="serial_number">Numéro de série</string>
-    <string name="standby_time">Dernière mise à jour</string>
+    <string name="tp">FW</string>
+    <string name="serial_number">SN</string>
+    <string name="standby_time">MODEL</string>
     <string name="update">Mise à jour</string>
     <string name="About">A propos du robot</string>
     <string name="are_you_sure_to_restore_factory_settings">Etes-vous sûre de réinitialiser les paramètres?</string>

+ 3 - 1
BusinessCommon/src/main/res/values/strings.xml

@@ -85,7 +85,7 @@ Nanfang plus client is an online information platform developed and operated by
     <string name="update_the_recipes">Update the recipes</string>
     <string name="apk">APK</string>
     <string name="mcu">MCU</string>
-    <string name="tp">FIRMWARE</string>
+    <string name="tp">FW</string>
     <string name="serial_number">SN</string>
     <string name="standby_time">MODEL</string>
     <string name="update">Update</string>
@@ -261,6 +261,8 @@ Nanfang plus client is an online information platform developed and operated by
     <string name="sovs_vide">SOVS VIDE</string>
     <string name="auto_clean">AUTO CLEAN</string>
     <string name="network_error">network error</string>
+    <string name="apk_version_latest">The app version is already up to date.</string>
+    <string name="installing">Installing...</string>
 
 
 </resources>

+ 3 - 0
BusinessMain/src/main/java/com/develop/main/ui/ModeEntranceActivity.kt

@@ -7,6 +7,7 @@ import android.widget.ImageView
 import androidx.appcompat.widget.AppCompatTextView
 import androidx.lifecycle.MutableLiveData
 import androidx.recyclerview.widget.RecyclerView
+import androidx.room.Update
 import com.alibaba.android.arouter.facade.annotation.Route
 import com.develop.base.ext.isNightTheme
 import com.develop.base.ext.navigateTo
@@ -21,6 +22,7 @@ import com.develop.common.router.Screens
 import com.develop.common.tag.*
 import com.develop.common.ui.CommonBindingActivity
 import com.develop.common.utils.AppVersionUtil
+import com.develop.common.utils.UpdateUtil
 import com.develop.common.widget.EntranceData
 import com.develop.common.widget.EntranceItemView
 import com.develop.common.widget.EntranceType
@@ -192,6 +194,7 @@ class ModeEntranceActivity : CommonBindingActivity<ActivityModeEntranceBinding>(
     override fun onResume() {
         super.onResume()
         AppVersionUtil.checkRecipeUpdate(false)
+        UpdateUtil.checkApkVersion()
     }
 
 

+ 99 - 11
BusinessSetting/src/main/java/com/develop/setting/ui/AboutActivity.kt

@@ -1,15 +1,21 @@
 package com.develop.setting.ui
 
-import android.content.ComponentName
-import android.content.Context
-import android.content.Intent
+import android.app.Activity
+import android.app.PendingIntent
+import android.content.*
+import android.content.pm.PackageInstaller
+import android.content.pm.PackageManager
+import android.net.Uri
 import android.os.Build
 import android.os.Bundle
+import android.os.ResultReceiver
 import android.provider.Settings
+import android.util.Log
 import android.view.LayoutInflater
 import android.view.View
 import android.widget.Toast
 import android.widget.RelativeLayout
+import androidx.core.content.FileProvider
 import com.alibaba.android.arouter.facade.annotation.Route
 import com.azhon.appupdate.listener.OnDownloadListener
 import com.blankj.utilcode.util.AppUtils
@@ -33,7 +39,8 @@ import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevStatus
 import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevStatusEvent
 import com.kuyuntech.cofarcooking.device.sdk.util.core.CofarSDK
 import org.greenrobot.eventbus.Subscribe
-import java.io.File
+import java.io.*
+import java.nio.charset.Charset
 
 
 @Route(path = Screens.Setting.ABOUT)
@@ -124,6 +131,24 @@ class AboutActivity : CommonBVMActivity<ActivityAboutBinding, AboutViewModel>()
             AppVersionUtil.checkRecipeUpdate(true)
         }
 
+        binding.updateFirmware.setOnClickListener{
+            val packageName = "com.abupdate.fota_demo_iot"
+            val intent = packageManager.getLaunchIntentForPackage(packageName)
+
+            if (intent != null) {
+                // 存在可以处理的应用程序
+                // 启动应用程序
+                startActivity(intent)
+            } else {
+                // 未找到指定包名的应用程序
+            }
+
+        }
+
+        binding.updateApk.setOnClickListener{
+
+        }
+
         binding.ivLogo.setOnClickListener {
             weightAlignCount++
             if (weightAlignCount >= 7) {
@@ -153,8 +178,11 @@ class AboutActivity : CommonBVMActivity<ActivityAboutBinding, AboutViewModel>()
         }
 
         commonDialog.msg = getString(com.develop.common.R.string.update_msg)
+        commonDialog.title = getString(com.develop.common.R.string.update)
+
         commonDialog.hasOKBtn = false
         cancelConfirmDialog.title = getString(com.develop.common.R.string.update_title)
+        val ctx = this;
         cancelConfirmDialog.onDialogClickListener =
             object : CancelConfirmDialog.OnDialogClickListener {
                 override fun onConfirm() {
@@ -171,9 +199,11 @@ class AboutActivity : CommonBVMActivity<ActivityAboutBinding, AboutViewModel>()
 
                             override fun done(apk: File) {
                                 GlobalToast.showToast(getString(com.develop.common.R.string.finish_download))
-                                runOnUiThread {
-                                    commonDialog.removeSelf()
-                                }
+                                installPackage(ctx,apk)
+//                                runOnUiThread {
+//                                    commonDialog.removeSelf()
+//                                }
+                                commonDialog.updateProgress(getString(com.develop.common.R.string.installing))
                             }
 
                             override fun downloading(max: Int, progress: Int) {
@@ -197,7 +227,7 @@ class AboutActivity : CommonBVMActivity<ActivityAboutBinding, AboutViewModel>()
                             }
 
                             override fun start() {
-                                GlobalToast.showToast(getString(com.develop.common.R.string.start_download))
+//                                GlobalToast.showToast(getString(com.develop.common.R.string.start_download))
                             }
 
                         })
@@ -208,8 +238,8 @@ class AboutActivity : CommonBVMActivity<ActivityAboutBinding, AboutViewModel>()
                 }
             }
 
-        binding.tvUpdate.setOnClickListener {
-            cancelConfirmDialog.showDialog(supportFragmentManager, "cancelConfirmDialog")
+        binding.updateApk.setOnClickListener {
+            UpdateUtil.checkApkVersion()
         }
 
         binding.tvAppVersion.setOnClickListener{
@@ -262,16 +292,74 @@ class AboutActivity : CommonBVMActivity<ActivityAboutBinding, AboutViewModel>()
         viewModel.devInfoLiveData.observe(this) {
             updateApkUrl = it?.apkUrl ?: ""
             if (it?.apkUpdate == true) {
-                binding.tvUpdate.visibility = View.VISIBLE
+//                binding.tvUpdate.visibility = View.VISIBLE
+                binding.updateApk.performClick()
             } else {
                 binding.tvUpdate.visibility = View.INVISIBLE
             }
+            binding.updateApk.visibility = View.VISIBLE
+            binding.updateFirmware.visibility = View.VISIBLE
+        }
+
+    }
+
+
+    fun installPackage(context: Context, apk: File) {
+        try {
+            val packageInstaller = context.packageManager.packageInstaller
+
+            val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL)
+
+            val sessionId = packageInstaller.createSession(params)
+            val session = packageInstaller.openSession(sessionId)
+
+            addApkToSession(apk, session)
+
+            val intent = Intent(context, InstallResultReceiver::class.java)
+            val pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
+
+            session.commit(pendingIntent.intentSender)
+
+            session.close()
+        } catch (e: Exception) {
+            e.printStackTrace()
+        }
+    }
+
+    private fun addApkToSession(file: File, session: PackageInstaller.Session) {
+        file.inputStream().use { inputStream ->
+            session.openWrite("COSU", 0, -1).use { outputStream ->
+                val buffer = ByteArray(4096)
+                var length: Int
+                while (inputStream.read(buffer).also { length = it } != -1) {
+                    outputStream.write(buffer, 0, length)
+                }
+            }
         }
+    }
 
+    class InstallResultReceiver : BroadcastReceiver() {
+        override fun onReceive(context: Context, intent: Intent) {
+            val extras: Bundle? = intent.extras
+            if (extras != null) {
+                val status = extras.getInt(PackageInstaller.EXTRA_STATUS)
+                // 处理安装结果
+                // status 是安装结果代码
+                // 可以使用PackageInstaller.Session的常量来解释结果
+
+                val message = extras.getString(PackageInstaller.EXTRA_STATUS_MESSAGE)
+                // 如果需要,可以获取附加的结果信息
+            }
+        }
     }
 
 
 
+
+
+
+
+
     fun togglePointerLocation(context: Context) {
         val currentSetting = Settings.System.getInt(context.contentResolver, "pointer_location", 0)
         val newSetting = if (currentSetting == 0) 1 else 0

+ 48 - 0
BusinessSetting/src/main/res/layout/activity_about.xml

@@ -79,6 +79,9 @@
             android:textSize="@dimen/convert_36px" />
     </LinearLayout>
 
+
+
+
     <LinearLayout
         android:id="@+id/function_layout"
         android:layout_width="@dimen/convert_650px"
@@ -103,6 +106,29 @@
                 android:textColor="@color/about_function_title"
                 android:textSize="@dimen/convert_30px" />
 
+
+            <LinearLayout
+                android:id="@+id/update_apk"
+                android:layout_width="wrap_content"
+                android:paddingEnd="@dimen/convert_24px"
+                android:paddingStart="@dimen/convert_24px"
+                android:paddingTop="@dimen/convert_12px"
+                android:paddingBottom="@dimen/convert_12px"
+                android:layout_height="wrap_content"
+                android:background="@drawable/about_update_btn_stoke"
+                android:layout_toStartOf="@id/tv_app_version"
+                android:layout_marginEnd="@dimen/convert_24px"
+                android:layout_centerVertical="true"
+                android:visibility="invisible"
+                android:orientation="horizontal">
+                <androidx.appcompat.widget.AppCompatTextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:text="@string/update"
+                    android:textColor="@color/about_update_recipes"
+                    android:textSize="@dimen/convert_16px" />
+            </LinearLayout>
+
             <androidx.appcompat.widget.AppCompatTextView
                 android:id="@+id/tv_app_version"
                 android:layout_width="wrap_content"
@@ -179,6 +205,28 @@
                 android:textColor="@color/about_function_title"
                 android:textSize="@dimen/convert_30px" />
 
+            <LinearLayout
+                android:id="@+id/update_firmware"
+                android:layout_width="wrap_content"
+                android:paddingEnd="@dimen/convert_24px"
+                android:paddingStart="@dimen/convert_24px"
+                android:paddingTop="@dimen/convert_12px"
+                android:paddingBottom="@dimen/convert_12px"
+                android:layout_height="wrap_content"
+                android:background="@drawable/about_update_btn_stoke"
+                android:layout_toStartOf="@id/tv_firmware"
+                android:layout_marginEnd="@dimen/convert_24px"
+                android:layout_centerVertical="true"
+                android:visibility="invisible"
+                android:orientation="horizontal">
+                <androidx.appcompat.widget.AppCompatTextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:text="@string/update"
+                    android:textColor="@color/about_update_recipes"
+                    android:textSize="@dimen/convert_16px" />
+            </LinearLayout>
+
             <androidx.appcompat.widget.AppCompatTextView
                 android:id="@+id/tv_firmware"
                 android:layout_width="wrap_content"

+ 6 - 2
app/build.gradle

@@ -9,8 +9,9 @@ plugins {
 
 
 ext{
-    versionCode=Integer.parseInt(new SimpleDateFormat("yyMMddHH").format(new Date()) + new Random().nextInt(10))
-    brandCode="000A"
+//    versionCode=Integer.parseInt(new SimpleDateFormat("yyMMddHH").format(new Date()) + 0)
+    versionCode=230617180
+    brandCode="010D"
     model="1039"
 }
 
@@ -23,6 +24,9 @@ android {
 
     }
 
+
+
+
     defaultConfig {
         applicationId "com.develop.foodcooking"
         minSdk 21

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -21,6 +21,7 @@
     <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
     <uses-permission android:name="android.permission.WAKE_LOCK" />
+    <uses-permission android:name="android.permission.INSTALL_PACKAGES" />
 
     <uses-permission
         android:name="android.permission.WRITE_SETTINGS"

+ 3 - 0
app/src/main/java/com/develop/foodcooking/FoodCookingApp.kt

@@ -81,6 +81,9 @@ class FoodCookingApp : BaseApp() {
             Settings.System.SCREEN_OFF_TIMEOUT,
             (1000 * 60 * minute).toInt()
         )
+
+        Settings.Secure.putInt(contentResolver,Settings.Secure.INSTALL_NON_MARKET_APPS,1)
+
         val uri: Uri = Settings.System
             .getUriFor(Settings.System.SCREEN_OFF_TIMEOUT)
         contentResolver.notifyChange(uri, null)

+ 2 - 2
app/src/main/java/com/develop/foodcooking/MainActivity.kt

@@ -16,8 +16,8 @@ class MainActivity : AppCompatActivity() {
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         val isNight = !isNightTheme()
-//        ThemeSkinService.getInstance().switchThemeSkin(0)
-//        setNightTheme(false)
+        ThemeSkinService.getInstance().switchThemeSkin(1)
+        setNightTheme(true)
         if (MMkvUtils.getBool(FIRST_IN)) {
             navigateTo(Screens.Main.ENTRANCE_CHOSEN)
         } else {

+ 18 - 0
app/src/main/res/xml/file_paths.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<paths xmlns:android="http://schemas.android.com/apk/res/android">
+    <external-path
+        name="external"
+        path="." />
+    <external-files-path
+        name="external_files"
+        path="." />
+    <cache-path
+        name="cache"
+        path="." />
+    <external-cache-path
+        name="external_cache"
+        path="." />
+    <files-path
+        name="files"
+        path="." />
+</paths>

+ 2 - 1
libThirdPart/build.gradle

@@ -64,7 +64,7 @@ dependencies {
     api "com.youth.banner:banner:2.1.0"
     api 'com.google.android.flexbox:flexbox:3.0.0'
     api 'com.yanzhenjie:permission:2.0.3'
-    api 'io.github.azhon:appupdate:4.2.4'
+    api 'io.github.azhon:appupdate:4.2.9'
     api 'cn.aigestudio.wheelpicker:WheelPicker:1.1.3'
 
     //------------------------------业务功能库-------------------------------------
@@ -91,6 +91,7 @@ dependencies {
     api 'com.github.CoderAlee.PaintedSkin:constraintlayout-compat:3.5.2.1'
     // 需要替换字体库时引入
     api 'com.github.CoderAlee.PaintedSkin:typeface-plugin:3.5.2.1'
+    compile 'com.github.a-voyager:AutoInstaller:v1.0'