获得程序apk全路径名,获取文件的md5值,向线性布局中添加View对象

来源:互联网 发布:常德第七元素网络 编辑:程序博客网 时间:2024/05/16 19:29

56.获得程序apk完整路径名

List<ApplicationInfo> infos = pm.getInstalledApplications(0);

for(ApplicationInfo info : infos){

String sourceDir = info.sourceDir;

}

检查手机病毒其实就是获得apk文件的MD5码,然后到病毒数据库查看是否存在该MD5.


获取文件的md5值

private String getFileMD5(String path){try {File file = new File(path);MessageDigest digest = MessageDigest.getInstance("md5");FileInputStream fis = new FileInputStream(file);byte[] buffer = new byte[1024];int len = -1;while((len = fis.read(buffer)) != -1){digest.update(buffer, 0, len);}file.close();byte[] result = digest.digest();StringBuffer sb = new StringBuffer();for(byte b : result){            int num = b & 0xff;              String str = Integer.toHexString(num);              if (str.length() == 1) {                  sb.append("0");              }              sb.append(str);}return sb.toString();} catch (Exception e) {e.printStackTrace();return "";}}

向线性布局中添加View对象

ll.addView(view);默认是添加到线性布局中的最下方,如果想添加到最上方可以用:

ll.addView(view, 0);

0 0