Can not RECIEVE SMS on my messaging app
martinLory opened this issue · 6 comments
I have a third party messaging app which I registered to the S2MSP application. The registration is done with no problem and the application shows on registered apps with the phone numbers that I specified. Once I add the SMS receiving implementation to my SMS Listener, the app stops receiving messages from all numbers even the registered ones.
my on receive function:
List<Sms> receivedSms = getSmsFromIntent(context, intent);
receivedSms.stream().filter(sms -> SecureSmsProxyFacade.PHONE_NUMBER_LOOPBACK.equals(sms.getNumber()));
for (Sms sms : receivedSms) {
......
}
my getSmsFromIntent function:
private static List<Sms> getSmsFromIntent(Context context, Intent intent) {
SecureSmsProxyFacade s2msp = SecureSmsProxyFacade.instance(context);
return s2msp.extractReceivedSms(intent, null);
}
The secret is null because I did not define it in the registration
Hope someone can show the exact steps to implement the SMS receiving function
Hi @martinLory
Leafing the secret null will not work. You get a secret when you register a number on the S2MSP app. You have to keep this secret for sending and receiving SMS.
You can find a working implementation in my project frimtec/pikett-assist.
I could not figure out how to define a secret the same way it was defined in the pikket-assist project, I would appreciate it if you could mention what exactly is the secret and how should I define it.
The secret is generated by S2MSP on registration and returned in the ActivityResult:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == YOUR_REQUEST_CODE) {
RegistrationResult result = s2msp.getRegistrationResult(resultCode, data);
result.getSecret().ifPresent(secret -> {/* store the secret permanently for later SMS communication */});
if (result.getReturnCode().isSuccess()) {
Toast.makeText(this, "Registration OK.", Toast.LENGTH_LONG).show();
...
} else {
Toast.makeText(this, "Registration FAILED: " + result.getReturnCode().name(), Toast.LENGTH_LONG).show();
...
}
}
...
}
The secret can be stored in your app in the DB or in the preferences.
For sending and receiving you just pass that secret and all is fine.
Hope that helps.
ok understood,
One other problem is that the messaging app I am trying to implement the project on receives the message as a pdus and subscriptionId and not as an SMS, how could I implement the function to it?
public void onReceive(Context context, Intent intent) {
Log.w("SMSListener", "Got SMS broadcast...");
if ((intent.getAction().equals(SMS_DELIVERED_ACTION)) || (intent.getAction().equals(SMS_RECEIVED_ACTION)) && isRelevant(context, intent))
{
Object[] pdus = (Object[]) intent.getExtras().get("pdus");
int subscriptionId = intent.getExtras().getInt("subscription", -1);
ApplicationContext.getInstance(context).getJobManager().add(new SmsReceiveJob(context, pdus, subscriptionId));
abortBroadcast();
}
}
This is the original onRecieve function
Thanks for your help
No, with S2MSP you have a slightly other abstraction. The Sms contains the numer, SMS text and subscriptionId.
public class YourSmsListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if ("your.application.package.SMS_RECEIVED".equals(intent.getAction())) {
List<Sms> receivedSms = getSmsFromIntent(context, intent);
for (Sms sms : receivedSms) {
...
}
}
}
private static List<Sms> getSmsFromIntent(Context context, Intent intent) {
SecureSmsProxyFacade s2msp = SecureSmsProxyFacade.instance(context);
String secret = ...; // secret from your registration
return s2msp.extractReceivedSms(intent, secret);
}
...
Please read the repositories README.md page first - it should all be in there 😉
Thanks
Hi @martinLory
I will close the issue for now.
If you have further troubles integrating your app with S2MSP, where you don't find an answer in the README.md, just reopen the issue.
If your have any suggestions to improve the documentation in the README.md, feel free to let me know.
Thanks, frimtec