How to handle OTP sent to another device?

Hello,
I am testing an app which sends OTP to the given number, but the device I am running my test cases on is different and so the OTP is sent to another device. Now I wanted to handle this scenario.
I didn’t get any solution for this so I asked user for console input (using scanner class in JAVA) and then entered the console value to the otp field. But this is very inefficient and i cannot get terminal inputs if i try to run test cases on cloud(like DEVICE FARM or VS appcenter) .

Could you please suggest any another efficient and full-proof way to handle this situation?

Thank You.