Q1 is a p-channel MOSFET. Here is the schematic with its terminals labeled (G = gate, D = drain, S = source):
A MOSFET turns on (allows current to flow) when the voltage between its gate and source, or Vgs, exceeds a threshold voltage, Vth. For P-channel MOSFETs, Vth is negative, which means that the gate has to be lower than the source by some amount for the MOSFET to turn on.
When Vin is high, current flows through the diode D1 to the load, making the voltage at the source approximately Vin (minus the diode drop). Since the gate is tied directly to Vin, this means that Vgs is slightly positive and Q1 remains off.
When Vin is low, the gate is pulled to ground by Rpull (a pull-down resistor). But wait, how does Q1 turn on if the source needs to be at a higher voltage than the gate, and in order for a voltage to appear at the source, Q1 needs to be on?
Well, there's a little diode at the bottom of the MOSFET symbol; this represents the body diode (sometimes called a parasitic diode), which is basically an artifact of the way the MOSFET is made. The presence of the body diode means that even when the MOSFET is off, it will only block current from flowing from the source to the drain; it will still allow current to flow from the drain to the source. Here, that's a good thing: the body diode allows current from the battery to flow from the drain to the source, bringing the source up to near the battery voltage and creating a negative Vgs voltage difference that allows the MOSFET to fully turn on.
The purpose of Q1 and D1 are to ensure that current only flows from Vin to the load or from the battery to the load, preventing reverse current from Vin to the cell or vice versa. Replacing Q1 with another diode would accomplish pretty much the same thing:
The advantage of the MOSFET is that, when it's on, there's less of a voltage drop across it compared to a diode. Less voltage drop means less power wasted, which is especially important when you're powering your load from a battery.
The Maxim (was Dallas Semi) DS2711 and DS2712 NiMh chargers include functionality to detect primary (i.e. non-rechargeable) cells. They do this by measuring the internal impedance of the cells, and using that to differentiate between NiMh (lower impedance) and primary cells (higher impedance), as explained in this Maxim Application Note 3388.
The abstract from that AppNote says:
The DS2711 and DS2712 Loose Cell NiMH Chargers (designed for one or
two AA or AAA NiMH "loose" cells) detect an alkaline primary cell and
avoid charging it. This application note characterizes a wide variety
of used and new cells from a variety of manufacturers and shows how
the charger ICs can distinguish between NiMH rechargeable cells and
alkaline primary cells.
Unfortunately for your application, as you can see in that abstract, those Maxim devices are designed for recharging 1 or 2 cells - not your 3-cell design. Options include modifying your design to use only 1 or 2 cells and, if your design needs it, adding a boost converter to match the higher output voltage of 3 cells (assuming the existing 3-cell design has them connected in series) or trying to incorporate the same impedance measurement technique as they use, into your own design (but perhaps check for any patents that might apply, if you do that).
Best Answer
What you describe is theoretically possible, but very inefficient, and probably not feasible. Proof:
\$3V\$ at \$2mA\$ is \$6mW\$. This is how much power you need to receive to make your thing work. The question is this: how much do you have to transmit?
If you have a \$1W\$ transmitter attached to an isotropic radiator (such things don't exist, but we will address that later), then for any sphere centered on that radiator, there is \$1W\$ of power. But, this power is spread out over a sphere of increasing area as we get farther away. This is the inverse square law. Knowing this, we can calculate the field strength from your \$1W\$ isotropic radiator at some distance \$r\$, by taking that \$1W\$ of power and dividing it by the surface area of a sphere. At \$20km\$, the field strength from your \$1W\$ isotropic radiator is:
$$ \frac{1W}{4 \pi (20km)^2} \approx 199pW/m^2 $$
Let's just say on your device you have made an antenna that can collect all the RF energy passing through a square meter. You will then receive 199pW, which isn't anywhere near the \$6mW\$ you need. In fact, you need about thirty thousand times more (\$6mW / 199pW \approx 30151\$). You could invest in a \$30kW\$ transmitter, but that's probably not what you had in mind.
You can make this system more efficient by sending less energy into space where your receiving device isn't. That is, you can use a directional antenna. We need an antenna that is 30151 times stronger than an isotropic radiator in the direction of the receiving device. That is, we need a gain of \$ 10 log(30151) \approx 45dBi \$. (more about dBi) You could get about that from a very directional antenna, like one with a large parabolic reflector.
So, if you can have a big, directional antenna, you can aim it at your device (hard, because the antenna is so directional), and your receiver can collect all the energy in a \$1m^2\$ area (probably not possible, if you want it to be small), you could power your device with a \$1W\$ transmitter. You are still not very efficient:
$$ 6mW / 1W = 0.6 \text{% efficient} $$
and all of those assumptions are pretty generous. By the time you take into account other inefficiencies in the system, the practicalities of making these devices small, aiming the antenna, etc, RF power transmission doesn't sound so great.
How about a solar panel? The sun is also an isotropic radiator of electromagnetic energy, and it's far away, and suffers from the same inefficiencies. But, it's free, and transmits at a power of about \$383YW\$, (solar luminosity) with the field strength being as much as \$1kW/m^2\$ at Earth's surface (Earth's insolation).