首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

不要Root权限获取已经安装的Apk安装包

2013-10-08 
不用Root权限获取已经安装的Apk安装包在安卓设备上安装的apk都会被保留一份在/data/app目录下,但是该目录

不用Root权限获取已经安装的Apk安装包

    在安卓设备上安装的apk都会被保留一份在/data/app目录下,但是该目录对于普通用户来说只有可执行权限,是无法访问的。

    但是其子文件具有可读权限。

    不要Root权限获取已经安装的Apk安装包

    意思也就说我们直接去查看/data/app这个目录是没办法的,但是通过写死文件的绝对路径是可以得到这个文件的。

    

/*** @Description 将app由data/app目录拷贝到sd卡下的指定目录中* @param appId 应用程序的ID号,如com.wondertek.jttxl* @param dest 需要将应用程序拷贝的目标位置* @date 2013-7-24 下午3:32:12*/private String backupApplication(String appId, String dest) {if (appId == null || appId.length() == 0 || dest == null || dest.length() == 0) { return "illegal parameters";}Util.Trace("[backupApplication] appId: " + appId + ", dest:" + dest);// check file /data/app/appId-1.apk existsString apkPath = "/data/app/" + appId + "-1.apk";File apkFile = new File(apkPath);if (apkFile.exists() == false) {return apkPath +  " doesn't exist!";}FileInputStream in = null;try {in = new FileInputStream(apkFile);} catch (FileNotFoundException e) {e.printStackTrace();return e.getMessage();}// create dest folder if necessaryint i = dest.lastIndexOf('/');if (i != -1) {File dirs = new File(dest.substring(0, i));dirs.mkdirs();dirs = null;}// do file copy operationbyte[] 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();return e.getMessage();}if (in != null) {try {in.close();} catch (IOException e) {e.printStackTrace();return e.getMessage();}}}return "success";}
    目前存在一个问题,就是有的文件后缀名不是1,这个不知道除了人为判断有没有2或3之外有没有其他更好的办法

热点排行