安卓软件防止安装包被二次打包
try
{
PackageInfo packageInfo = getPackageManager().getPackageInfo(packname, PackageManager.GET_SIGNATURES);
Signature[] signs = packageInfo.signatures;
Signature sign = signs[0];
int code = sign.hashCode();
if (code!=xxxxxxx)//xx为事先计算出来的
{
Toast.makeText(this,"软件被二次打包",Toast.LENGTH.LONG).show();
//第一次可以让toast显示code值,然后把它替换掉xxxxxx
//这个是算签名的,记得不能用debug的签名,否则别人修改你的安装后,用debug签名,,,,就没用了
}
}
catch (PackageManager.NameNotFoundException e)
{}