Open rynkowsg opened 2 weeks ago
@rynkowsg Where do you call session.await()
? It will cancel the session when the coroutine scope it was launched in is cancelled. It may be that you're calling await()
in a coroutine scope with short lifecycle.
it doesn't work for me neither.
I have a function like follows:
private fun installAPK(apkFile: File) = lifecycleScope.launch(Dispatchers.IO) {
val packageInstaller = PackageInstaller.getInstance(this@AppReleaseActivity)
val packageUninstaller = PackageUninstaller.getInstance(this@AppReleaseActivity)
val apkUri = uriFromFile(applicationContext, apkFile)
try {
val session = packageInstaller.createSession(InstallParameters
.Builder(apkUri)
.setName("release-app.apk")
.setRequireUserAction(true)
.build()
)
session.progress
.onEach { progress -> {
Timber.d("PROG" + session.id +" - "+ progress)
}}
.launchIn(this)
when (session.await()) {
is SessionResult.Success -> {
println("Success")
}
is SessionResult.Error -> {
println(result.cause.message)
}
}
} catch (_: CancellationException) {
println("Cancelled")
} catch (exception: Exception) {
println(exception)
}
}
But it does nothing, any log in logcat, and any action even if I set .setRequireUserAction(true)
, debugging the app, it never enters into when() { ...
sentence, and not throwing eny exception type also :(
Any help will be appreciate it.
@eriknyk Are you sure that your lifecycleScope
isn't cancelled in the meantime?
@solrudev it is tied to the currect activity lifecycleScope, and the activity is active & visible, so the scope wan't cancelled. any thoughts?
@eriknyk Please, provide a minimal reproducible example. It's important to see a broader picture of how the library is used, because there's no problem in your code snippet.
@solrudev here you go -> https://github.com/eriknyk/demoinstallapk
if you uncomment line :74 (https://github.com/eriknyk/demoinstallapk/blob/main/app/src/main/java/com/github/eriknyk/demoinstallapk/MainActivity.kt#L74)
and comment line :73, you will se that installAPK_Other()
forks fine and install the apk as expected, and the installAPK()
doesn't work using Ackpine
Regards.
@eriknyk
The problem in your sample is that you're using DEFERRED
session confirmation and don't allow notifications to be posted.
In your AndroidManifest.xml
you've disabled AckpineInitializer
which creates a notification channel for (un)install confirmation notifications. Also you didn't request POST_NOTIFICATIONS
permission. If you change confirmation to IMMEDIATE
while creating the session, or if you fix the things mentioned, Ackpine will work.
it worked with the changes thank you! (136aca9)
I just have a last questions, not sure what is supposed .setRequireUserAction(true/false)
should to do?
I've tried setting it true
and false
on both cases the confirm dialog to install the app is displayed.
@eriknyk
what is supposed
.setRequireUserAction(true/false)
should to do?
It configures the PackageInstaller.SessionParams#setRequireUserAction() parameter. Also it's mentioned in library's docs.
@rynkowsg Have you solved the issue with stuck sessions? Maybe some comments in this thread were helpful?
I tried to use Ackpine but I can't make it to work. This is pretty much what I try to run:
I get in logs:
Some other time just gets stuck on 79% and stay there.
If I use same
apkFileUri
and use Android PackageInstaller and I commit session directly works with no issue.I tested both solutions, with Ackpine and without on Android 13 as a normal app, and on Android 7 as a system app. In both cases, Ackpine got stuck and simple session based solution works.
I'm using v0.6.1.
Any advice?