4

是否可以获取应用程序上次更新的日期?我想像这样在应用程序中显示它:

  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));
4

2 回答 2

3

尝试这个 :

PackageManager pm = context.getPackageManager();
ApplicationInfo appInfo = pm.getApplicationInfo("app.package.name", 0);
String appFile = appInfo.sourceDir;
long installed = new File(appFile).lastModified(); //Epoch Time
于 2013-05-25T10:48:52.157 回答
1

此方法以字符串格式返回上次更新的日期,例如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;
}
于 2016-12-19T21:16:54.397 回答