Apk Update Code Added
This commit is contained in:
@@ -34,9 +34,12 @@ import `in`.sminnovations.hpostesting.BuildConfig
|
|||||||
import `in`.sminnovations.hpostesting.R
|
import `in`.sminnovations.hpostesting.R
|
||||||
import `in`.sminnovations.hpostesting.databinding.ActivityDashboardBinding
|
import `in`.sminnovations.hpostesting.databinding.ActivityDashboardBinding
|
||||||
import okhttp3.ResponseBody
|
import okhttp3.ResponseBody
|
||||||
|
import java.io.BufferedInputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
import java.util.zip.ZipInputStream
|
||||||
|
|
||||||
interface NatsMessageCallback {
|
interface NatsMessageCallback {
|
||||||
fun onMessageReceived(topic: String, message: String)
|
fun onMessageReceived(topic: String, message: String)
|
||||||
@@ -92,20 +95,17 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
|||||||
when (result) {
|
when (result) {
|
||||||
is Result.Success -> {
|
is Result.Success -> {
|
||||||
// Handle success
|
// Handle success
|
||||||
val apkUrl = result.data
|
val apk = result.data
|
||||||
val responseBodyString = apkUrl.string()
|
|
||||||
|
|
||||||
|
|
||||||
val fileToWriteTo = File(this.getExternalFilesDir(null), "downloaded_file.apk")
|
val fileToWriteTo = File(this.getExternalFilesDir(null), "downloaded_file.apk")
|
||||||
|
|
||||||
apkUrl.byteStream().use { inputStream ->
|
apk.byteStream().use { input ->
|
||||||
FileOutputStream(fileToWriteTo).use { outputStream ->
|
fileToWriteTo.outputStream().use { output ->
|
||||||
inputStream.copyTo(outputStream)
|
input.copyTo(output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d(TAG, "Responsebody: $responseBodyString")
|
Log.d("Responsebodyformat", "Responsebodyformat: ")
|
||||||
installApk(fileToWriteTo)
|
installApk(fileToWriteTo)
|
||||||
Log.e("ApI", "APK URL: $apkUrl")
|
Log.e("ApI", "APK URL: $apk")
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
this,
|
this,
|
||||||
"${result.data}",
|
"${result.data}",
|
||||||
@@ -203,6 +203,34 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun unzip(zipFilePath: String, outputFolderPath: String) {
|
||||||
|
ZipInputStream(BufferedInputStream(FileInputStream(zipFilePath))).use { zis ->
|
||||||
|
var zipEntry = zis.nextEntry
|
||||||
|
val buffer = ByteArray(1024)
|
||||||
|
|
||||||
|
while (zipEntry != null) {
|
||||||
|
val fileName = zipEntry.name
|
||||||
|
val newFile = File(outputFolderPath, fileName)
|
||||||
|
|
||||||
|
if (zipEntry.isDirectory) {
|
||||||
|
newFile.mkdirs()
|
||||||
|
} else {
|
||||||
|
// Create all parent directories
|
||||||
|
newFile.parent?.let { File(it).mkdirs() }
|
||||||
|
|
||||||
|
FileOutputStream(newFile).use { fos ->
|
||||||
|
var len: Int
|
||||||
|
while (zis.read(buffer).also { len = it } > 0) {
|
||||||
|
fos.write(buffer, 0, len)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zipEntry = zis.nextEntry
|
||||||
|
}
|
||||||
|
zis.closeEntry()
|
||||||
|
}
|
||||||
|
}
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user