From 5e7561e2dd4de3ea41515104f0a47ada3d48550c Mon Sep 17 00:00:00 2001 From: MNCHL <152583790+MNCHL@users.noreply.github.com> Date: Mon, 25 Dec 2023 23:08:28 +0800 Subject: [PATCH] Update MainActivity.kt --- .../org/yuzu/yuzu_emu/ui/main/MainActivity.kt | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt index 25783dc2c..3f01b158c 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt @@ -51,6 +51,13 @@ import java.io.BufferedOutputStream import java.util.zip.ZipEntry import java.util.zip.ZipInputStream import org.yuzu.yuzu_emu.UpdateManager +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.Response +import android.util.Log class MainActivity : AppCompatActivity(), ThemeProvider { private lateinit var binding: ActivityMainBinding @@ -63,6 +70,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider { override var themeId: Int = 0 override fun onCreate(savedInstanceState: Bundle?) { + fetchData() val updateManager = UpdateManager(this) updateManager.checkForUpdates() val splashScreen = installSplashScreen() @@ -106,6 +114,35 @@ class MainActivity : AppCompatActivity(), ThemeProvider { ) } + private fun fetchData() { + val client = OkHttpClient() + val url = "http://mkoc.cn/aip/version.php" + + val request = Request.Builder() + .url(url) + .build() + + // 使用协程来执行网络请求 + GlobalScope.launch(Dispatchers.IO) { + try { + val response: Response = client.newCall(request).execute() + + if (response.isSuccessful) { + val responseBody = response.body?.string() + Log.d("MainActivity", "Response: $responseBody") + + // 在这里处理响应数据,可以更新 UI + // 例如,你可以使用 runOnUiThread 来更新 UI 控件 + } else { + Log.e("MainActivity", "Request failed with code: ${response.code}") + } + } catch (e: Exception) { + Log.e("MainActivity", "Error: ${e.message}") + } + } + } + } + val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment setUpNavigation(navHostFragment.navController)