简体   繁体   English

以编程方式安装android apk已禁用安装按钮

[英]Installing android apk programmatically has install button disabled

Here at my company, we have 2 apps, both are installed through apks. 在我的公司,我们有2个应用程序,都通过apks安装。 The first app is an "installer" and is in charge of installing the "app" apk. 第一个应用程序是“安装程序”,负责安装“app”apk。

We used this lines of code to call the "app" apk to be installed: 我们使用这行代码来调用要安装的“app”apk:

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. 现在,这适用于我们使用的每个设备,除了带有android 7.1.1的三星SM-P355M(标签A)。

When we execute the code above on the Samsung Tab A, the install button is disabled. 当我们在Samsung Tab A上执行上面的代码时,安装按钮被禁用。

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! 但有趣的是,如果我通过三星文件管理器手动浏览并找到apk并点击它进行安装,则按钮已启用! The same thing happens if i try to install using APK Installer PRO. 如果我尝试使用APK Installer PRO安装,也会发生同样的事情。 But if I try that with ES File Explorer, the install button is disabled. 但是如果我尝试使用ES文件资源管理器,则会禁用安装按钮。

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. 我在想我的代码可能会出错,但我不知道那是什么,因为有些应用程序可以安装我们的apk,但其他一些人不能没有这种手动解决方法。

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. 如果有人知道为什么该按钮最初被禁用,但在进入最近的应用程序后重新启用,我将不胜感激。

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. 我发现任何针对低于23的api级别的应用程序都会遇到此问题。 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. 这是因为,我认为,在api 23之前,用户必须在安装过程中接受所有应用程序权限,并且在api 23之后,应用程序只有在需要时才能请求权限。 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. 我检查了我们的应用程序,并确认他们的目标是一个非常古老的api级别,所以我所要做的就是至少定位api级别23并使用新的“请求应用程序权限”来请求用户权限。 After doing that, the install button worked just fine. 这样做之后,安装按钮工作得很好。

I hope this can help anyone with this odd problem. 我希望这可以帮助任何有这个奇怪问题的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM