v1.0.9 - 메인 및 설정 화면 상단 빈 여백 완전 제거 및 인앱 APK 원클릭 업데이트 복원
This commit is contained in:
@@ -20,8 +20,8 @@ android {
|
||||
applicationId = "com.example.shiftalarm"
|
||||
minSdk = 26
|
||||
targetSdk = 35
|
||||
versionCode = 108
|
||||
versionName = "1.0.8"
|
||||
versionCode = 109
|
||||
versionName = "1.0.9"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
@@ -93,6 +94,16 @@
|
||||
android:foregroundServiceType="mediaPlayback"
|
||||
android:exported="false" />
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.provider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/provider_paths" />
|
||||
</provider>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -108,16 +108,7 @@ object AppUpdateManager {
|
||||
|
||||
btnNow.setOnClickListener {
|
||||
dialog.dismiss()
|
||||
try {
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(apkUrl)).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
activity.startActivity(intent)
|
||||
Toast.makeText(activity, "최신 버전 다운로드 페이지로 이동합니다.", Toast.LENGTH_SHORT).show()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Toast.makeText(activity, "다운로드 링크 열기 실패: ${e.message}", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
downloadAndInstallApk(activity, apkUrl, version)
|
||||
}
|
||||
|
||||
dialog.show()
|
||||
@@ -125,4 +116,100 @@ object AppUpdateManager {
|
||||
val width = (activity.resources.displayMetrics.widthPixels * 0.88).toInt()
|
||||
dialog.window?.setLayout(width, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
|
||||
private fun downloadAndInstallApk(activity: Activity, apkUrl: String, version: String) {
|
||||
if (activity.isFinishing || activity.isDestroyed) return
|
||||
|
||||
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_update_progress_oneui, null)
|
||||
val tvSub = view.findViewById<TextView>(R.id.tvProgressSub)
|
||||
val progressBar = view.findViewById<ProgressBar>(R.id.downloadProgressBar)
|
||||
val tvPercent = view.findViewById<TextView>(R.id.tvProgressPercent)
|
||||
|
||||
tvSub.text = "v$version 다운로드 중..."
|
||||
|
||||
val progressDialog = AlertDialog.Builder(activity)
|
||||
.setView(view)
|
||||
.setCancelable(false)
|
||||
.create()
|
||||
|
||||
progressDialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||
progressDialog.show()
|
||||
|
||||
val width = (activity.resources.displayMetrics.widthPixels * 0.88).toInt()
|
||||
progressDialog.window?.setLayout(width, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
|
||||
Thread {
|
||||
try {
|
||||
val url = URL(apkUrl)
|
||||
val connection = url.openConnection() as HttpURLConnection
|
||||
connection.connectTimeout = 15000
|
||||
connection.readTimeout = 15000
|
||||
connection.requestMethod = "GET"
|
||||
connection.connect()
|
||||
|
||||
val fileLength = connection.contentLength
|
||||
val inputStream = BufferedInputStream(connection.inputStream)
|
||||
|
||||
val apkFile = File(activity.cacheDir, "update.apk")
|
||||
val outputStream = FileOutputStream(apkFile)
|
||||
|
||||
val buffer = ByteArray(8192)
|
||||
var total: Long = 0
|
||||
var count: Int
|
||||
|
||||
while (inputStream.read(buffer).also { count = it } != -1) {
|
||||
total += count
|
||||
outputStream.write(buffer, 0, count)
|
||||
|
||||
if (fileLength > 0) {
|
||||
val progress = (total * 100 / fileLength).toInt()
|
||||
activity.runOnUiThread {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
progressBar.setProgress(progress, true)
|
||||
} else {
|
||||
progressBar.progress = progress
|
||||
}
|
||||
tvPercent.text = "$progress%"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
outputStream.flush()
|
||||
outputStream.close()
|
||||
inputStream.close()
|
||||
connection.disconnect()
|
||||
|
||||
activity.runOnUiThread {
|
||||
progressDialog.dismiss()
|
||||
installApk(activity, apkFile)
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
activity.runOnUiThread {
|
||||
progressDialog.dismiss()
|
||||
Toast.makeText(activity, "다운로드 실패: ${e.message}", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
private fun installApk(activity: Activity, apkFile: File) {
|
||||
try {
|
||||
val apkUri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
FileProvider.getUriForFile(activity, "${activity.packageName}.provider", apkFile)
|
||||
} else {
|
||||
Uri.fromFile(apkFile)
|
||||
}
|
||||
|
||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||
setDataAndType(apkUri, "application/vnd.android.package-archive")
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
}
|
||||
activity.startActivity(intent)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Toast.makeText(activity, "설치 실패: ${e.message}", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,9 +63,7 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v, insets ->
|
||||
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
val density = resources.displayMetrics.density
|
||||
val p = (8 * density).toInt()
|
||||
v.setPadding(systemBars.left + p, systemBars.top + p, systemBars.right + p, systemBars.bottom + p)
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
||||
insets
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
android:id="@+id/headerRoot"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:paddingHorizontal="20dp"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingTop="32dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingStart="24dp"
|
||||
android:paddingEnd="24dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
||||
Reference in New Issue
Block a user