get App Last Update Time - Android App

Android examples for App:APK Information

Description

get App Last Update Time

Demo Code


//package com.java2s;

import java.util.Date;
import android.content.Context;

import android.content.pm.PackageInfo;

import android.content.pm.PackageManager.NameNotFoundException;

public class Main {

    public static final Date getLastUpdateTime(Context context,
            String packageName) {
        return new Date(getPackageInfo(context, packageName).lastUpdateTime);
    }/*from w  w  w. jav a 2 s .  c  o  m*/

    public static final PackageInfo getPackageInfo(Context context) {
        return getPackageInfo(context, context.getPackageName(), 0);
    }

    public static final PackageInfo getPackageInfo(Context context,
            String packageName) {
        return getPackageInfo(context, packageName, 0);
    }

    public static final PackageInfo getPackageInfo(Context context,
            int flags) {
        return getPackageInfo(context, context.getPackageName(), flags);
    }

    public static final PackageInfo getPackageInfo(Context context,
            String packageName, int flags) {
        PackageInfo info = null;
        try {
            info = context.getPackageManager().getPackageInfo(packageName,
                    flags);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return info;
    }
}

Related Tutorials