This commit is contained in:
parent
b451e694f4
commit
776eb9daae
|
|
@ -17,6 +17,8 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import androidx.core.content.FileProvider
|
||||
import com.stand.standapp.net.NetworkModule
|
||||
import okhttp3.*
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
|
|
@ -56,11 +58,41 @@ class UpdateManager(private val context: Context) {
|
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) it.longVersionCode.toInt() else it.versionCode
|
||||
}
|
||||
} catch (e: Exception) { 0 }
|
||||
val currentVersionName = try {
|
||||
context.packageManager.getPackageInfo(context.packageName, 0).versionName
|
||||
} catch (e: Exception) { "" }
|
||||
|
||||
val url = "$serverUrl/api/app-version/check-update?versionCode=$currentVersionCode"
|
||||
// 获取详细设备和尺寸属性
|
||||
val deviceId = android.provider.Settings.Secure.getString(context.contentResolver, android.provider.Settings.Secure.ANDROID_ID) ?: "unknown_android"
|
||||
val displayMetrics = context.resources.displayMetrics
|
||||
val screenWidth = displayMetrics.widthPixels
|
||||
val screenHeight = displayMetrics.heightPixels
|
||||
val screenDensity = displayMetrics.density.toString()
|
||||
val loginAccount = AppConfig.getSavedUsername(context)
|
||||
|
||||
val jsonParams = JSONObject().apply {
|
||||
put("versionCode", currentVersionCode)
|
||||
put("versionName", currentVersionName)
|
||||
put("deviceId", deviceId)
|
||||
put("deviceType", "接警终端")
|
||||
put("deviceBrand", Build.BRAND)
|
||||
put("deviceModel", Build.MODEL)
|
||||
put("osVersion", "Android " + Build.VERSION.RELEASE)
|
||||
put("screenWidth", screenWidth)
|
||||
put("screenHeight", screenHeight)
|
||||
put("screenDensity", screenDensity)
|
||||
put("loginAccount", loginAccount)
|
||||
}
|
||||
|
||||
val url = "$serverUrl/api/app-version/check-update"
|
||||
val mediaType = "application/json; charset=utf-8".toMediaType()
|
||||
val requestBody = jsonParams.toString().toRequestBody(mediaType)
|
||||
|
||||
val client = NetworkModule.defaultClient
|
||||
val request = Request.Builder().url(url).build()
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.post(requestBody)
|
||||
.build()
|
||||
|
||||
client.newCall(request).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue