The Dynamic Framed-ALOHA (DFA) protocol is studied for wireless sensor networks with energy limitations and energy-harvesting capability. The performance of DFA in this scenario is evaluated in terms of the time efficiency (or throughput), which is routinely used to evaluate medium access protocols, and by introducing a new metric, referred to as detection efficiency, which is tailored to scenarios with energy constraints. Specifically, detection efficiency measures the ability of a multiple access protocol to collect data from nodes without depleting their energy reserves. Analysis is first performed by assuming that DFA is operated with a perfect backlog (i.e., number of sensors left to be interrogated) knowledge. Then, a low-complexity backlog estimation algorithm is presented, which is shown by numerical results to perform close to the ideal case of perfect backlog knowledge.