如何以编程方式获取应用程序的.apk文件 [英] How to get the .apk file of an application programmatically

查看:66
本文介绍了如何以编程方式获取应用程序的.apk文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个具有以下功能的应用程序.它应该保存它的 .apk 文件添加到 sdcard .假设我有一个Button.单击它后,我必须保存应用程序的 .apk 文件.

I want to create an application which has the following functionality. It should save its .apk file to the sdcard. Imagine I have a Button. On clicking it I have to save the .apk file of the application.

推荐答案

很容易做到..

  1. 首先,您将获得所有已安装的应用程序,
  2. 每个,获取公共源目录.
  3. 将文件复制到SD卡.

注意:无需植根.

以下是代码段:

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> apps = getPackageManager().queryIntentActivities(mainIntent, 0);
for (ResolveInfo info : apps) {
    File file = new File(info.activityInfo.applicationInfo.publicSourceDir);
    // Copy the .apk file to wherever
}

这篇关于如何以编程方式获取应用程序的.apk文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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