Biomedical electronics plays a crucial role in bridging the gap between engineering and medicine by enabling the development of miniaturized medical equipment offering efficient diagnosis as well as treatment for various diseases. However, despite the recent advances in wearable biomedical devices, the key power source, the battery, is often toxic and hazardous to human beings as it can result in severe gastrointestinal injuries if swallowed accidentally. Chargeable ingestible batteries developed in this research hold the potential of accelerating the development of safer medical technologies as they can offer high biocompatibility, non-toxicity, and global environmental sustainability. Herein, we developed a hydrogel-based ingestible battery which employs the selective ionic diffusion resulting due to the salinity gradient. Potassium chloride (KCl)-absorbed agarose hydrogels were used for creating different salinity gradients. A cation-selective gellan gum (GG) membrane allows the selective migration of ions within the system, hence generating an open-circuit potential difference up to 177 mV. The shapes of the mold of the battery were designed by a 3D printer so that it can adapt to a variety of devices. The battery can be further charged via a self-charging triboelectric nanogenerator (TENG) resulting in the generation of sufficient voltage (300 mV). We applied the electricity to stimulate the bacterial solution (containing E. coli), killing or deactivating about 90% of the bacteria just 30 minutes after the treatment. Hence, this technology is very promising for fighting antibiotic-resistant bacteria in the gastrointestinal tract, such as the oral cavity, as well as for providing a harmless energy source to medical devices.