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

查看:291
本文介绍了android - 手机已经安装的软件但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";
}

这篇关于android - 手机已经安装的软件但apk被手动删除了、请问有办法能找回apk来吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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