Android to determine debug signature and release signature

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.