1
votes

Is there a way to detect the app which is sending the intercepted SMS?

In my code I can intercept both outgoing and incoming SMS, read body, phone number etc but I don't know if there is a way to detect the app/package which is sending the SMS. I have searched but had no luck. Thanks in advance. I am using the below library to intercept short messages:

Sms Radar on GitHub

Note that I'm not talking about the app which is the default messaging app. Sometimes other apps like WhatsApp send SMS to authenticate the user. These type of SMS won't be visible inside outbox/sent messages, although I can detect them at the point of send/receive.

So I just want to know exactly which app (package name) is right now sending the SMS.

2

2 Answers

1
votes

AFAIK you cannot detect which app is sending the SMS. It's just not saved in the content storage.

However, you could use an error-prone workaround:
list all apps currently running which have the SEND_SMS permission (possibly with internet permission as well) when the SMS is sent.

Another (untested) way might be to read the stack in the onSmsSent() using Thread.currentThread().getStackTrace() by iterating over the returned array until you reach an application which can sent SMS. But I guess this won't work as Android is most likely to proxy any changes made to the content storage.

0
votes

So I found a workaround. During when an app is sending a short message, it is a foreground process. So I just got the list of foreground processes when my onSMSSent() got called and found the app that is sending SMS, at the top of the list.

Though this might not be a solid solution, but as @Ch4t4r said, it seems there is no solution to directly get the SMS sending app and the trick sounds good enough.