必須加入一個編譯時間來做識別, 如何紀錄編譯時間呢?
很簡單, 首先在build.gradle(Module: app) 裡面的android { } 加入紅框框內容
這樣在每次編譯後,都會紀錄下編譯的時間,接下來我們介紹一下要如何取出這個值
TextView date=(TextView)findViewById(R.id.date); Date buildDate = new Date(BuildConfig.TIMESTAMP); // 直接格式化輸出現在時間的方法 SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS"); date.setText(sdFormat.format(buildDate));
參考資料:
http://stackoverflow.com/questions/7607165/how-to-write-build-time-stamp-into-apk


沒有留言:
張貼留言