以编程方式重新安装应用程序apk而不下载 [英] Reinstall application apk programmatically without downloading

查看:83
本文介绍了以编程方式重新安装应用程序apk而不下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于这个恼人的Android限制我需要用户重新安装我的应用程序,以便其他应用程序检测到清单权限。

Due to this annoying Android limitation I need users to reinstall my application so the manifest permissions are detected by other applications.

这对用户来说已经是令人沮丧的了,但另外,我看不到从/ data / app中存储的apk重新安装我的应用程序的方法因此,在解雇通常的安装意图之前,必须将相同的版本下载到存储卡。

This is already going to be frustrating for the user, but in addition, I cannot see a way to reinstall my application from the apk stored in /data/app and I would therefore have to download the same version to the storage card before firing the usual install intent.

我急切等待有人告诉我,我错过了一些明显的东西!我已经画了一个空白...

I eagerly await someone telling me that I'm missing something obvious! I've drawn a blank...

提前致谢。

如果你有问题,那就明白这个问题吧我希望看到它解决了!干杯。

Please do star the issue if you'd like to see it resolved! Cheers.

编辑:考虑到@hackbod的评论,你可以使用以下代码启动安装对话框。

EDIT: With the comments of @hackbod in mind, you can use the following code to initiate the install dialog.

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(this.getApplicationInfo().sourceDir)),
"application/vnd.android.package-archive");
startActivity(intent);

在我的Jelly Bean设备上,这提供了两个选项:包安装程序验证并安装。我不知道后者是否会处理以下问题:

On my Jelly Bean device, this presents two options: Package installer and Verify and install. I don't know if the latter will deal with the issue of:


  • 以这种方式安装你的应用程序可能会删除所有权它来自Play商店

  • Installing your app this way will probably remove ownership of it from the Play Store

我的申请是免费的,所以我无法测试付费的问题:

My application is free, so I cannot test the paid issue of:


  • 但是请注意,如果您的应用程序是正向锁定的(由于应用程序加密,这对于从JB开始的所有付费应用程序都是不可避免的),那么因为你的应用程序可执行文件不被其他人读取而无法正常工作

  • Note however if your app is forward locked (which is unavoidable for all paid applications starting with JB, due to the app encryption), then this won't work because your app executable is not readable by others

尽管hackbod以其他人可读结束建议如果您通过自己的代码执行此操作,对于您自己的应用程序,它是可读的?如果你可以测试这个我错了,请纠正我。

Although hackbod finishes with 'readable by others' which suggests that if you are executing this through your own code, for your own application, it is readable? Please do correct me if you can test this and I'm wrong.

推荐答案

可以想象你可以得到你的路径。 apk通过Context.getApplicationInfo()。sourceDir,并使用该路径启动应用程序安装程序。但是,如果您的应用程序是正向锁定的(由于应用程序加密,这对于从JB开始的所有付费应用程序都是不可避免的),那么这将无效,因为其他人无法读取您的应用程序可执行文件。在这种情况下,您需要将.apk复制到世界可读的地方(例如在外部存储中)并从那里安装。

Conceivably you could just get the path to your .apk through Context.getApplicationInfo().sourceDir, and launch the app installer with that path. Not however if your app is forward locked (which is unavoidable for all paid applications starting with JB, due to the app encryption), then this won't work because your app executable is not readable by others. In that case you would need to copy the .apk to somewhere world readable (such as in external storage) and install it from there.

无论你在这里做什么,但是,这有一些不可避免的非常不利的后果:

No matter what you do here, though, this has some unavoidable very negative consequences:


  • 从你的应用程序进行任何类型的安装的唯一方法是通过侧面加载UI,这是(a)对用户来说将是一个非常可怕的体验,并且(b)将要求用户打开侧载以便能够继续。

  • 以这种方式安装您的应用程序可能会从Play商店中删除它的所有权(因为它不再是安装它的人)。这可能意味着例如用户不能再通过游戏商店向您报告崩溃或ANR,或其他负面后果。我不确定这里究竟会出现什么样的问题,但我真的不会认为这样就好了。

最终,我只是不建议这样做。你需要什么许可强迫你这样做?出于多种原因,我不建议第三方应用程序在大多数情况下声明自己的权限,因为围绕权限的许多不良用户体验只有在需要之后才会知道。

Ultimately, I just would very much not suggest doing this. What permission are you needing that is forcing you to do this? For many reasons, I wouldn't recommend that third party applications declare their own permissions in most cases, because there are a lot of bad user experiences around permissions that are only known after they may have been needed.

这篇关于以编程方式重新安装应用程序apk而不下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆