Here, we demonstrate self-powered ultraviolet photodetectors that are capable of generating opposite current flow when illuminated at different wavelengths. The photodetectors are composed of n-ZnO/Polyaniline (PANI) p-n and PANI/ZnGa2O4 type-II heterojunctions and operate without any need for external power source. Devices display superior stability in ambient conditions within months. Results provide opportunities for developing devices for optical recognition.