2013-05-25 44 views
3

是否可以獲取應用上次更新的日期? 我想表明它在應用程序是這樣的:Android應用獲取上次更新日期

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

回答

2

試試這個:

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

此方法返回的最後一次更新的字符串格式一樣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; 
}