- With App Lifecycle 應用程式重裝前都不會改變
- With Andoird OS Profile Lifecycle 作業系統Reset to factory前都不會改變
@SuppressLint("HardwareIds")
private fun getHardwareId() : String {
var output = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
if(output == "") {
val pref = this.getSharedPreferences("HardwareIds", Context.MODE_PRIVATE)
output = pref.getString("hardware_id","").orEmpty()
if(output == "") {
output = UUID.randomUUID().toString()
val editor = pref.edit()
editor.putString("hardware_id", output)
editor.apply()
}
}
return output
}