如何从android设备获取apk文件?或者如何将apk文件从设备传输到系统?


当前回答

在unix系统上,您可以尝试这个函数:

function android_pull_apk() {
    if [ -z "$1" ]; then
        echo "You must pass a package to this function!"
        echo "Ex.: android_pull_apk \"com.android.contacts\""
        return 1
    fi

    if [ -z "$(adb shell pm list packages | grep $1)" ]; then
        echo "You are typed a invalid package!"
        return 1
    fi

    apk_path="`adb shell pm path $1 | sed -e 's/package://g' | tr '\n' ' ' | tr -d '[:space:]'`"
    apk_name="`adb shell basename ${apk_path} | tr '\n' ' ' | tr -d '[:space:]'`"

    destination="$HOME/Documents/Android/APKs"
    mkdir -p "$destination"

    adb pull ${apk_path} ${destination}
    echo -e "\nAPK saved in \"$destination/$apk_name\""
}

例如:android_pull_apk com.android.contacts 注意:识别包:adb shell pm列表包

其他回答

不需要root:

这段代码将获得第三方包的路径和名称,以便您可以轻松识别您的APK

adb shell pm list packages -f -3

输出将是

包:/ / app / XX.XX.XX.apk = YY.YY.YY数据

现在使用下面的代码拉出这个包:

adb pull /data/app/XX.XX.XX.apk

如果你在C:>\中执行上面的cmd命令,那么你会在那里找到这个包。

还有另一个bash脚本(即可以用于大多数基于unix的系统)。基于佩德罗·罗德里格斯的回答,但更容易使用。

对佩德罗版本的改进:

Original approach did not work for me on Android 7: adb pull kept complaining about no such file or directory while adb shell could access the file. Hence I used different approach, with temporary file. When launched with no arguments, my script will just list all available packages. When partial package name is provided, it will try to guess the full package name. It will complain if there are several possible expansions. I don't hardcode destination path; instead APKs are saved to current working directory.

保存到一个可执行文件:

#!/bin/bash
# Obtain APK file for given package from the device connected over ADB

if [ -z "$1" ]; then
    echo "Available packages: "
    adb shell pm list packages | sed 's/^package://'
    echo "You must pass a package to this function!"
    echo "Ex.: android_pull_apk \"com.android.contacts\""
    exit 1
fi

fullname=$(adb shell pm list packages | sed 's/^package://' | grep $1)
if [ -z "$fullname" ]; then
    echo "Could not find package matching $1"
    exit 1
fi
if [ $(echo "$fullname" | wc -l) -ne 1 ]; then
    echo "Too many packages matched:"
    echo "$fullname"
    exit 1
fi
echo "Will fetch APK for package $fullname"

apk_path="`adb shell pm path $fullname | sed -e 's/package://g' | tr '\n' ' ' | tr -d '[:space:]'`"
apk_name="`basename ${apk_path} | tr '\n' ' ' | tr -d '[:space:]'`"

destination="${fullname}.apk"

tmp=$(mktemp --dry-run --tmpdir=/sdcard --suffix=.apk)
adb shell cp "${apk_path}" "$tmp"
adb pull "$tmp" "$destination"
adb shell rm "$tmp"

[ $? -eq 0 ] && echo -e "\nAPK saved in \"$destination\""

想要非常非常舒服的一分钟解决方案吗?

只需你这个应用程序https://play.google.com/store/apps/details?id=com.cvinfo.filemanager(智能文件管理器从谷歌发挥)。

点击“应用程序”,选择一个,然后点击“备份”。它将在你的文件系统的app_backup文件夹;)

如果你知道(或者你能“猜”到)。apk的路径(它的格式似乎是/data/app/com.example.someapp-{1,2,..}.apk to),那么你也可以从/data/app中复制它。这个功能甚至在我的非根安卓手机上也能运行。

只需使用终端模拟器应用程序(比如这个)并运行:

# step 1: confirm path
ls /data/app/com.example.someapp-1.apk
# if it doesn't show up, try -2, -3. Note that globbing (using *) doesn't work here.
# step 2: copy (make sure you adapt the path to match what you discovered above)
cp /data/app/com.example.someapp-1.apk /mnt/sdcard/

然后你可以把它从sd卡移到任何你想要的地方(或附加到电子邮件等)。最后一点在技术上可能是可选的,但它使您在尝试使用.apk文件时更加轻松。

打开你想从你的手机上提取apk的应用程序。 获取当前打开的应用程序: adb shell dump活动活动| grep mFocusedActivity 获取包名的路径 Adb shell PM path <packagename.apk>

4.将您获得的路径复制到sdcard目录

    adb shell cp /data/app/<packagename.apk> /sdcard

5.拉apk

    adb pull /sdcard/base.apk

Edit

如果第2步不起作用,使用以下方法:

adb shell dumpsys window windows | grep mCurrentFocus