首页 > 手机已经安装的软件但apk被手动删除了、请问有办法能找回apk来吗?

手机已经安装的软件但apk被手动删除了、请问有办法能找回apk来吗?

手机已经安装的软件但apk被手动删除了、请问有办法能找回apk来吗?


可以获取当前安装应用的APK

public static String backupApplication(Context context,String packageName, String dest) {
    if (packageName == null || packageName.length() == 0

    || dest == null || dest.length() == 0) {
        return "illegal parameters";
    }
    PackageManager pm = context.getPackageManager();   
    PackageInfo pi = null;
    try {
        pi = pm.getPackageInfo(context.getPackageName(), 0);
    } catch (NameNotFoundException e1) {
        e1.printStackTrace();
    }   
    // check file /data/app/appId-1.apk exists
    Log.i("",""+pi.applicationInfo.sourceDir);
    String apkPath = "/data/app/" + packageName + "-1.apk";

    File apkFile = new File(apkPath);

    if (!apkFile.exists()) {
        apkFile=new File(pi.applicationInfo.sourceDir);
        if(!apkFile.exists()){
            return apkPath + " doesn't exist!";
        }
    }

    FileInputStream in;

    try {
        in = new FileInputStream(apkFile);

    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return e.getMessage();
    }

    // create dest folder if necessary

    int i = dest.lastIndexOf('/');

    if (i != -1) {
        File dirs = new File(dest.substring(0, i));
        dirs.mkdirs();
    }

    // do file copy operation

    byte[] c = new byte[1024];

    int slen;

    FileOutputStream out = null;

    try {
        out = new FileOutputStream(dest);

        while ((slen = in.read(c, 0, c.length)) != -1)
            out.write(c, 0, slen);
    } catch (IOException e) {
        e.printStackTrace();
        return e.getMessage();
    } finally {
        if (out != null)
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        try {
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return "success";
}

如果确定手机上的apk已经删除了那么只能靠工具来还原组装一个apk出来(apk本身是一个程序和资源的压缩包,安装的过程就是一个解压和注册的过程)。
你可以试试apk share这个软件,运行软件后选择app然后点backup就会还原apk文件并放在你的sdcard里。

【热门文章】
【热门文章】