MD5介绍
http://baike.baidu.com/link?url=WicTvWv2haI7QrJdoPK0asQbQEujnJ9-iU6G_N2L2H4fwK6hsdkE6Rw1H9Gi_iVHiVhK4SzUfoZcYvzQ3lInSK
方法实现
/**
* 获取文件的md5值
* @param path 文件的全路径名称
* @return 文件的md5值
*/
public static String getFileMd5(String path){
try {
// 获取一个文件的特征信息,签名信息。
File file = new File(path);
// md5
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);
}
byte[] result = digest.digest();
StringBuffer sb = new StringBuffer();
for (byte b : result) {
// 与运算
int number = b & 0xff;// 加盐
String str = Integer.toHexString(number);
// System.out.println(str);
if (str.length() == 1) {
sb.append("0");
}
sb.append(str);
}
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
apk文件所在目录
//用户自己安装的应用apk文件在data/app目录下
//系统安装的应用apk文件在system/app目录下
String path=getApplicationContext().getPackageResourcePath();