Jaytjuh
Jaytjuh

Reputation: 1083

Android app get last date updated

Is it possible to get the date when the app was last updated? I want to show it in the app like this:

  String htmltext = "E-mail: " + Datacontainer.Instance().GetDatabaseHelper().GetUserEmail() +
                    "<br>Authorized: " + is_auth +
                    "<br>Last updated on: " + "?" +
                    "<br>Tips version: " + "228" +
                    "<br>App version: " + "v 1.3.0" +
                    "<br>Your Airline: " + "?" +
                    "<br>Your Nickname: " + "?" +
                    "<br>No of tips submitted: " + "?";

  TextView infotext = (TextView)fragmentView.findViewById(R.id.infotext);
  infotext.setText(Html.fromHtml(htmltext));

Upvotes: 8

Views: 3567

Answers (2)

Al Lelopath
Al Lelopath

Reputation: 6778

This method returns the date of the last update in String format like 12/25/2016 10:38:02:

// get last update date
private String getLastUpdateDate() {

    PackageManager packageManager =  getActivity().getPackageManager();
    long updateTimeInMilliseconds; // install time is conveniently provided in milliseconds

    Date updateDate = null;
    String updateDateString = null;

    try {

        ApplicationInfo appInfo = packageManager.getApplicationInfo(getActivity().getPackageName(), 0);
        String appFile = appInfo.sourceDir;
        updateTimeInMilliseconds = new File(appFile).lastModified();
        updateDateString  = MiscUtilities.getDate(updateTimeInMilliseconds, "MM/dd/yyyy hh:mm:ss");

    }
    catch (PackageManager.NameNotFoundException e) {
        // an error occurred, so display the Unix epoch
        updateDate = new Date(0);
        updateDateString = updateDate.toString();
    }

    return updateDateString;
}

Upvotes: 1

Abdullah Shoaib
Abdullah Shoaib

Reputation: 2095

Try this :

PackageManager pm = context.getPackageManager();
ApplicationInfo appInfo = pm.getApplicationInfo("app.package.name", 0);
String appFile = appInfo.sourceDir;
long installed = new File(appFile).lastModified(); //Epoch Time

Upvotes: 4

Related Questions