Installing android apk programmatically has instal

2019-04-12 13:43发布

Here at my company, we have 2 apps, both are installed through apks. The first app is an "installer" and is in charge of installing the "app" apk.

We used this lines of code to call the "app" apk to be installed:

Uri apkUri = Uri.fromFile(toInstall);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
startActivityForResult(intent, RC_INSTALL);

Now, this works fine for every device we work with, EXCEPT the Samsung SM-P355M (Tab A) with android 7.1.1.

When we execute the code above on the Samsung Tab A, the install button is disabled.

Install button disabled

But if the user presses the Recent apps button, and then return to our "installer" app, the install prompt comes back with the install button enabled!

Install button re-enabled

I don't know why this is happening and why it only occurs on this particular device, and a lot of our users are having problems installing our app because they don't know this workaround.

An interesting thing though, is that if I manually browse and find the apk through the Samsung file manager and tap it to install, the button is enabled! The same thing happens if i try to install using APK Installer PRO. But if I try that with ES File Explorer, the install button is disabled.

I am thinking that there is something that I might be doing wrong with my code, but I have no idea what that is, because some apps can install our apk, but some others can't without that manual workaround.

I have tried to look for any installed apps that might have "draw over apps" permission, screen recorders, flux or anything similar, but have found nothing that could cause this issue.

If someone has any idea of why the button is disabled at first, but re-enabled after going into the recent apps, I'd be grateful.

1条回答
贼婆χ
2楼-- · 2019-04-12 14:15

I managed to fix this problem after a week of trying but forgot to post it here.

For future reference and to help anyone who might be as unlucky as I was to deal with this bug, I'll leave what I did here.

I found out that any app that targeted an api level below 23 would have this problem. This is because, I think, before api 23 all app permissions had to be accepted by the user at the time of it's install process, and after api 23 the app could ask for permission only when it needed it. I checked our apps and verified that they were targeting a very old api level, so all I had to do was to target at least api level 23 and use the new "Request App Permissions" to request permission to the user. After doing that, the install button worked just fine.

I hope this can help anyone with this odd problem.

查看更多
登录 后发表回答