Android 如何在没有 root 访问权限的情况下获取已安装应用的 APK?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11012976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get the APK of an installed app without root access?
提问by pinas
I'm trying to extract the APK file of an installed Android app WITHOUT root permissions.
我正在尝试在没有 root 权限的情况下提取已安装的 Android 应用程序的 APK 文件。
I thought that this was impossible, because all APK files for non-system-apps are located in /data/app, and accessing this folder requires root permission. Then I found that there are numerous apps in the Google Play store that seem to have access to the APK files even on non-rooted devices.
我认为这是不可能的,因为非系统应用程序的所有 APK 文件都位于 /data/app 中,并且访问此文件夹需要 root 权限。然后我发现 Google Play 商店中有许多应用程序似乎可以访问 APK 文件,即使在非 root 设备上也是如此。
Can someone tell me how this is possible? Aren't there backup apps which backup the APK files without root?
有人能告诉我这怎么可能吗?没有备份应用程序可以在没有root的情况下备份APK文件吗?
回答by mah
Accessing /data/app is possible without root permission; the permissions on that directory are rwxrwx--x. Execute permission on a directory means you can access it, however lack of read permission means you cannot obtain a listing of its contents -- so in order to access it you must know the name of the file that you will be accessing. Android's package manager will tell you the name of the stored apk for a given package.
无需root权限即可访问/data/app;该目录的权限是 rwxrwx--x。目录的执行权限意味着您可以访问它,但是缺少读取权限意味着您无法获得其内容列表——因此为了访问它,您必须知道您将要访问的文件的名称。Android 的包管理器会告诉您存储的给定包的 apk 的名称。
To do this from the command line, use adb shell pm list packages
to get the list of installed packages and find the desired package.
要从命令行执行此操作,请使用adb shell pm list packages
获取已安装包的列表并找到所需的包。
With the package name, we can get the actual file name and location of the APK using adb shell pm path your-package-name
.
通过包名,我们可以使用 .apk 获取 APK 的实际文件名和位置adb shell pm path your-package-name
。
And knowing the full directory, we can finally pull the adb using adb pull full/directory/of/the.apk
并且知道完整的目录,我们终于可以使用 adb pull full/directory/of/the.apk
Credit to @tarn for pointing out that under Lollipop, the apk path will be /data/app/your-package-name-1/base.apk
感谢@tarn 指出在 Lollipop 下,apk 路径将是 /data/app/your-package-name-1/base.apk
回答by Yojimbo
Android appends a sequence number to the package name to produce the final APK file name (it's possible that this varies with the version of Android OS). The following sequence of commands works on a non-rooted device:
Android 将序列号附加到包名称以生成最终的 APK 文件名(这可能因 Android 操作系统版本而异)。以下命令序列适用于非 root 设备:
Get the full path name of the APK file for the desired package.
adb shell pm path com.example.someapp
This gives the output as:
package:/data/app/com.example.someapp-2.apk
.Pull the APK file from the Android device to the development box.
adb pull /data/app/com.example.someapp-2.apk
获取所需包的 APK 文件的完整路径名。
adb shell pm path com.example.someapp
这使输出为:
package:/data/app/com.example.someapp-2.apk
。将 APK 文件从 Android 设备拉到开发盒中。
adb pull /data/app/com.example.someapp-2.apk
The location of APK after successful pulling will be at ../sdk/platform-tools/base.apk on your pc/laptop.
成功拉取后APK的位置将在您的PC/笔记本电脑上的../sdk/platform-tools/base.apk。
回答by Sagar Waghmare
You don't need ROOT permissions to get the list of Installed Apps.
您不需要 ROOT 权限即可获取已安装的应用程序列表。
You can do it with android PackageManager.
您可以使用 android PackageManager 来完成。
Below is a small code snippet.
下面是一个小代码片段。
final PackageManager pm = getPackageManager();
//get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d(TAG, "Installed package :" + packageInfo.packageName);
Log.d(TAG, "Apk file path:" + packageInfo.sourceDir);
}
回答by goldy021
- check the list of installed apk's (following command also list the path where it is installed and package name). adb shell pm list packages -f
- use adb pull /package_path/package name /path_in_pc(package path and package name one can get from above command 1.)
- 检查已安装的 apk 列表(以下命令还列出了安装路径和包名称)。 adb shell pm 列出包 -f
- 使用adb pull /package_path/package name /path_in_pc(包路径和包名称可以从上面的命令 1 中获得。)
回答by anon
When you have Eclipse for Android developement installed:
当您安装了用于 Android 开发的 Eclipse 后:
- Use your device as debugging device. On your phone: Settings > Applications > Development and enable USB debugging, see http://developer.android.com/tools/device.html
- In Eclipse, open DDMS-window: Window > Open Perspective > Other... > DDMS, see http://developer.android.com/tools/debugging/ddms.html
- If you can't see your device try (re)installing USB-Driver for your device
- In middle pane select tab "File Explorer" and go to system > app
- Now you can select one or more files and then click the "Pull a file from the device" icon at the top (right to the tabs)
- Select target folder - tada!
- 将您的设备用作调试设备。在您的手机上:设置 > 应用程序 > 开发并启用 USB 调试,请参阅 http://developer.android.com/tools/device.html
- 在 Eclipse 中,打开 DDMS-window:Window > Open Perspective > Other... > DDMS,参见http://developer.android.com/tools/debugging/ddms.html
- 如果您看不到您的设备,请尝试(重新)为您的设备安装 USB 驱动程序
- 在中间窗格中选择选项卡“文件资源管理器”并转到系统 > 应用程序
- 现在您可以选择一个或多个文件,然后单击顶部的“从设备中提取文件”图标(选项卡右侧)
- 选择目标文件夹 - 多田!
回答by Buhiire Keneth
On Nougat(7.0) Android version run adb shell pm list packages
to list the packages installed on the device.
Then run adb shell pm path your-package-name
to show the path of the apk.
After use adb to copy the package to Downloads adb shell cp /data/app/com.test-1/base.apk /storage/emulated/0/Download
.
Then pull the apk from Downloads to your machine by running adb pull /storage/emulated/0/Download/base.apk
.
在 Nougat(7.0) Android 版本上运行adb shell pm list packages
以列出设备上安装的软件包。然后运行adb shell pm path your-package-name
以显示apk的路径。使用 adb 将包复制到 Downloads 后adb shell cp /data/app/com.test-1/base.apk /storage/emulated/0/Download
。然后通过运行将 apk 从下载中拉到您的机器上adb pull /storage/emulated/0/Download/base.apk
。
回答by vanduc1102
I got a does not exist error
我有一个 does not exist error
Here is how I make it works:
这是我如何使它工作:
adb shell pm list packages -f | findstr zalo
package:/data/app/com.zing.zalo-1/base.apk=com.zing.zalo
adb shell
mido:/ $ cp /data/app/com.zing.zalo-1/base.apk /sdcard/zalo.apk
mido:/ $ exit
adb pull /sdcard/zalo.apk Desktop
/sdcard/zalo.apk: 1 file pulled. 7.7 MB/s (41895394 bytes in 5.200s)
回答by Pankaj Arora
List PackageManager.getInstalledApplications()will give you a list of the installed applications, and ApplicationInfo.sourceDir is the path to the .apk file.
List PackageManager.getInstalledApplications()将为您提供已安装应用程序的列表,ApplicationInfo.sourceDir 是 .apk 文件的路径。
// in oncreate
PackageManager pm = getPackageManager();
for (ApplicationInfo app : pm.getInstalledApplications(0)) {
Log.d("PackageList", "package: " + app.packageName + ", sourceDir: " + app.sourceDir);
}
//output is something like
D/PackageList(5010): package: com.example.xmlparse, sourceDir: /data/app /com.example.xmlparse-2.apk
D/PackageList(5010): package: com.examples.android.calendar, sourceDir: /data/app/com.examples.android.calendar-2.apk
D/PackageList(5010): package: com.facebook.katana, sourceDir: /data/app/com.facebook.katana-1.apk
D/PackageList(5010): package: com.facebook.samples.profilepicture, sourceDir: /data/app/com.facebook.samples.profilepicture-1.apk
D/PackageList(5010): package: com.facebook.samples.sessionlogin, sourceDir: /data/app/com.facebook.samples.sessionlogin-1.apk
D/PackageList(5010): package: com.fitworld, sourceDir: /data/app/com.fitworld-2.apk
D/PackageList(5010): package: com.flipkart.android, sourceDir: /data/app/com.flipkart.android-1.apk
D/PackageList(5010): package: com.fmm.dm, sourceDir: /system/app/FmmDM.apk
D/PackageList(5010): package: com.fmm.ds, sourceDir: /system/app/FmmDS.apk
回答by Swing
I found a way to get the APK's package name in a non-root device. it's not so elegant, but works all the time.
我找到了一种在非 root 设备中获取 APK 包名称的方法。它不是那么优雅,但一直有效。
Step 1: on your device, open the target APK
第 1 步:在您的设备上,打开目标 APK
Step 2: on PC cmd window, type this commands:
第 2 步:在 PC cmd 窗口中,键入以下命令:
adb shell dumpsys activity a > dump.txt
because the output of this command is numerous, redirect to a file is recommended.
因为这个命令的输出很多,所以建议重定向到一个文件。
Step 3: open this dump.txt file with any editor.
第 3 步:使用任何编辑器打开此 dump.txt 文件。
for device befor Android 4.4:
the beginning of the file would be looked like this:
对于 Android 4.4 之前的设备:
文件的开头如下所示:
ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
Main stack:
* TaskRecord{41aa9ed0 #4 A com.tencent.mm U 0}
numActivities=1 rootWasReset=true userId=0
affinity=com.tencent.mm
intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10600000 cmp=com.tencent.mm/.ui.LauncherUI}
realActivity=com.tencent.mm/.ui.LauncherUI
askedCompatMode=false
lastThumbnail=null lastDescription=null
lastActiveTime=19915965 (inactive for 10s)
* Hist #9: ActivityRecord{41ba1a30 u0 com.tencent.mm/.ui.LauncherUI}
packageName=com.tencent.mm processName=com.tencent.mm
the package name is in the 3rd line, com.tencent.mmfor this example.
包名在第三行,本例中为com.tencent.mm。
for Android 4.4 and later:
the dumpsys output has changed a little.
try search "Stack #1", the package name would be very close below it.
对于 Android 4.4 及更高版本:
dumpsys 输出略有变化。尝试搜索“Stack #1”,软件包名称将在其下方非常接近。
Also, search "baseDir", you will find the full path of the apk file!
另外,搜索“baseDir”,您将找到apk文件的完整路径!
回答by JenyaKh
Open ES explorer -> push Menu button at the left upper corner (three horizontal stripes) -> in the Libraries section choose APPs.
打开ES资源管理器->点击左上角的Menu按钮(三个横条)->在Libraries部分选择APPs。
Thus, you get the list of all the user apps. Find your app and select it with long pushing on it. Then press "More" in the right low corner and choose "Send". Then you can use different options, e.g. you can choose "ES Save To" in order to save the .apk file to your home directory or anywhere else.
因此,您将获得所有用户应用程序的列表。找到您的应用程序并长按选择它。然后按右下角的“更多”并选择“发送”。然后您可以使用不同的选项,例如您可以选择“ES Save To”以将 .apk 文件保存到您的主目录或其他任何地方。