Skip to content
Advertisement

Installing apk that updates the same app fails on Android 10; java.lang.SecurityException: Files still open

Our app downloads an APK from our server, and runs this to upgrade itself. As mentioned in Android 10 – No Activity found to handle Intent and Xamarin Android 10 Install APK – No Activity found to handle Intent, this does not work as previously if the mobile device has been upgraded to Android 10, getting “No Activity found to handle Intent”.

We’ve tried to rewrite this using PackageInstaller as in the example https://android.googlesource.com/platform/development/+/master/samples/ApiDemos/src/com/example/android/apis/content/InstallApkSessionApi.java, but now get this error instead:

JavaScript

Here’s the code we use:

JavaScript

Target SDK is set to API 23 to be able to support old devices some customers have. We’re using Qt as the app framework, but Java for native Android functions like this.

Some thoughts on this:
* In Xamarin Android 10 Install APK – No Activity found to handle Intent, they mention that they need to do extra garbage collection in Xamarin. Maybe it’s because of the same issue we have here? If so, how could we get passed this in Java directly?
* We’re trying to upgrade the same app using a downloaded apk. Will this work at all using package installer? If not, do we then need to use a second app to upgrade the original?
* We also have a service running in the app as well for notifications, could this be causing the “Files still open” issue?

Advertisement

Answer

I was able to solve this by closing the InputStream and OutputStream. In addition, I had to check for SDK versions prior to 21, as we have minimum API 16 and PackageInstaller was added in API 21.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement