Determine debug signature and release signature
The idea is:
You can get the signature information in the package signature object, there is a hashcode () method in the Signature object, which can be used to identify the signature object.
At present, I use the method is to run the release version of the app, and then record the signature object in the package Hashcode, in the program to determine whether the Signature object hashcode is the same value, the same is release, Otherwise, it's debug.
Public Booleancheckappreleaseversion () {Try { //get the signature information in the package signature objectString PackageName =Context.getpackagename (); intFlags =Packagemanager.get_signatures; PackageInfo PackageInfo=pm.getpackageinfo (PackageName, flags); signature[] Signatures=Packageinfo.signatures; //take the first loaded activity signature byte[] cert = Signatures[0].tobytearray (); String strresult= ""; //Convert to MD5 character to determineMessageDigest MD; MD= Messagedigest.getinstance ("MD5"); Md.update (CERT); for(byteb:md.digest ()) { //byte turns into 16 binaryStrresult + = integer.tostring (b & 0xFF, 16); } strresult=strresult.touppercase (); //Debug if("De421d82d4bbf9042886e72aa31fe22". toUpperCase (). Equals (Strresult)) { return false; } //Relaease if("C96155c3dad4ca1069808fbac813a69". toUpperCase (). Equals (Strresult)) { return true; } } Catch(NoSuchAlgorithmException ex) {return false; } Catch(Packagemanager.namenotfoundexception ex) {return false; } return false;}
Android to determine debug signature and release signature