How to write build time stamp into apk

后端 未结 10 654
别跟我提以往
别跟我提以往 2020-12-02 07:57
  1. Making some changes in Android Contacts package
  2. Using mm (make) command to build this application

Because I have to change and

10条回答
  •  广开言路
    2020-12-02 07:59

    I use the same strategy as Pointer Null except I prefer the MANIFEST.MF file. This one is regenerated even if a layout is modified (which is not the case for classes.dex). I also force the date to be formated in GMT to avoid confusion between terminal and server TZs (if a comparison has to be made, ex: check latest version).

    It result in the following code:

      try{
         ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), 0);
         ZipFile zf = new ZipFile(ai.sourceDir);
         ZipEntry ze = zf.getEntry("META-INF/MANIFEST.MF");
         long time = ze.getTime();
         SimpleDateFormat formatter = (SimpleDateFormat) SimpleDateFormat.getInstance();
         formatter.setTimeZone(TimeZone.getTimeZone("gmt"));
         String s = formatter.format(new java.util.Date(time));
         zf.close();
      }catch(Exception e){
      }
    

提交回复
热议问题