get Compilation Date Time - Android App

Android examples for App:App Information

Description

get Compilation Date Time

Demo Code


//package com.java2s;
import android.app.Activity;

import android.content.pm.ApplicationInfo;

import android.util.Log;
import java.text.SimpleDateFormat;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {
    private final static String TAG = "AndroidUtil";

    public static String getCompilationDateTime(Activity activity) {
        try {/*from   w  ww . j  a  va  2  s .c o m*/
            ApplicationInfo ai = activity.getPackageManager()
                    .getApplicationInfo(activity.getPackageName(), 0);
            ZipFile zf = new ZipFile(ai.sourceDir);
            ZipEntry ze = zf.getEntry("classes.dex");
            long time = ze.getTime();
            String d = SimpleDateFormat.getInstance().format(
                    new java.util.Date(time));

            zf.close();
            return d;
        } catch (Exception e) {
            Log.e(TAG,
                    "Getting compilation date/time failed " + e.toString());
        }

        return "";
    }
}

Related Tutorials