The heterojunctions based transition metal carbide (MXenes) provides new possibilities for achieving high-performance photodetector. The electronic, mechanical, optical, and photocatalytic properties of the Hf2CO2-based heterojunctions are calculated based on first-principles calculations, and the photocurrent (Iph) and extinction ratio (ER) are calculated based on quantum transport simulations. The Hf2CO2/Sc2CF2, Hf2CO2/Zr2CO2, and Hf2CO2/Sc2CCl2 heterojunctions are ionic semiconductors with indirect bandgap. The Hf2CO2/Sc2CF2 heterojunction exhibits high solar to hydrogen efficiency (ηSTH) of 40.14 % and applying biaxial strain can effectively modulate the ηSTH of the Hf2CO2/Zr2CO2 heterojunction. The Hf2CO2/Zr2CO2 heterojunction has low overpotentials (ηHER) of 0.19 V and exhibits high electron mobility. The photodetector based on the Hf2CO2/Zr2CO2 heterojunction exhibits high Iph, and the photodetector based on the Hf2CO2/Sc2CF2 heterojunction has large ER and sensitivity to infrared and ultraviolet polarized light. The Iph and ER are significant increase by bending the photodetector. Our research indicates the potential applications of the Hf2CO2-based heterojunctions in photocatalytic water splitting and photodetector.