2014-11-17 47 views
-1
// Are we charging/charged? 

int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); 

//Determine the Current Battery Level 

int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); 
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1); 

裁判:http://developer.android.com/training/monitoring-device-state/battery-monitoring.html這段代碼中-1的意義或用法是什麼?

+2

如果找不到狀態,它可能是應該返回的默認值 – John

+1

@John:的確是缺省值。 [見'getIntExtra' here](http://developer.android.com/reference/android/content/Intent.html) – Amadan

+0

回答你的問題.. – John

回答

0

如果你看開發商documentation for this method,它會告訴你:

公衆詮釋getIntExtra(字符串名稱,詮釋默認值)

檢索擴展數據從意圖。

參數:

  • 所需項目的名稱。
  • defaultValue如果沒有給定名稱存儲所需類型的值,則返回該值。

返回:

如果沒有發現先前putExtra加入()項或者 默認值的值。