As already mentioned in Emmanuel, it is impossible to change the phone application without recompiling the operating system. Even on the root device, you are still locked in the vendor’s firmware and, at best, try to backtrack. Now you can receive notifications in certain types of events and preform actions, but I doubt that this is what you want to do.
However, for those who need to know what is happening under the hood, take a look here
For the exposed telephony interface (including SMS API) see android.telephony
source share