Answer the question
In order to leave comments, you need to log in
How to make the application automatically send SMS messages to the server?
Good afternoon!
I am writing an application, the essence of which is to send incoming SMS from a specific recipient to the wiremock service.
I did it first with a button when you click on which it sends, like, everything is cool.
But I need the application to automatically send SMS if it comes (from a specific user).
To do this, I decided to use IntentService, but it still doesn’t work, and as the message came, it was sent 1 time and that’s it.
Can you tell me in what way it is possible or through which class it is possible to implement so that the application constantly analyzes the SMS message and if it arrives, then by default it immediately sends it ??
Thanks in advance for any help.
Answer the question
In order to leave comments, you need to log in
1. We listen to SMS by the receiver so that it is processed earlier than by the default application, we set the priority higher
<receiver android:name=".sms.SmsReceiver" >
<intent-filter android:priority="1000" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null
&& intent.getAction() != null
&& ACTION.compareToIgnoreCase(intent.getAction()) == 0) {
Object[] pduArray = (Object[]) intent.getExtras().get("pdus");
SmsMessage[] messages = new SmsMessage[pduArray.length];
for (int i = 0; i < pduArray.length; i++) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
messages[i] = SmsMessage.createFromPdu(((byte[]) pduArray[i]), intent.getStringExtra(FORMAT));
} else {
messages[i] = SmsMessage.createFromPdu((byte[]) pduArray[i]);
}
String phone = messages[i].getOriginatingAddress();
String message = messages[i].getMessageBody();
}
}
}
abortBroadcast();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question