I'm currently working on a solution how to update and install APK file programmatically - very similar like this issue. My app doesn't use Google Services.
For updating purposes, APK-files with ascending versions are stored on an internal server and a C# Web service returns the latest version of the APK file.
I do this with Retrofit2:
@Streaming
@GET("/ws/webservice.svc/getUpdate")
fun getUpdate(
@Query("Programm") program: String,
@Query("version") version: String,
@Query("test") test: Boolean
): Single<String>
and LiveData:
override fun getUpdate() {
disposables += api.getUpdate(
program = context.getString(R.string.app_name),
version = context.getString(R.string.app_version),
test = isTest
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeBy(
onSuccess = {
liveData.value = GetUpdate(it)
},
onError = {
liveData.value = Error("Error getUpdate: " + it.message)
}
)
}
The problem that I'm facing, is that the response of that API call (which means - the latest APK file) has a base64String representation like shown in the image below - this is for example only a part of the server response when the API call is made in browser.
Is it somehow possible to generate a "real" APK file from this String representation after downloading it, so after that I can probably be able to install it on the device? I know that this is weird, but the customer wants me to re-use the same web service for this purposes.
I found a similar issue here. How can be this done in Kotlin? Thanks in advance.