I am currently developing a React Native app to send text messages. I successfully sent messages using smsManager.sendMultipartTextMessage(), but encountered an issue where some devices receive the messages as split parts. This seems to be a problem related to the carrier or the device itself, which I am unable to resolve. Therefore, I am looking to switch to sending MMS instead.
I tried using smsManager.sendMultimediaMessage() as described on this page: sendMultimediaMessage
However, I keep encountering failures, and I believe the issue might be related to creating the PDU file.
I referenced this site for the data format:
dataFormat
Despite numerous attempts, I haven’t been able to make it work, so I’m seeking help. How can I properly create the contentUri, which is the second parameter for smsManager.sendMultimediaMessage()?
The message should be sent in the background without opening the default messaging app.
my code is this
@ReactMethod
public void sendDirectSms(String phoneNumber, String msg) {
try {
SmsManager smsManager = SmsManager.getDefault();
// create MMS
ContentValues mmsValues = new ContentValues();
mmsValues.put(Telephony.Mms.SUBJECT, "Subject");
Uri mmsUri = this.context.getApplicationContext().getContentResolver().insert(Telephony.Mms.CONTENT_URI, mmsValues);
if (mmsUri == null) {
Log.e("SendDirectSms", "Failed to create MMS message.");
return;
}
String messageId = mmsUri.getLastPathSegment();
// add adress
Uri addrUri = Uri.withAppendedPath(mmsUri, "addr");
ContentValues addrValues = new ContentValues();
addrValues.put(Telephony.Mms.Addr.MSG_ID, messageId);
addrValues.put(Telephony.Mms.Addr.ADDRESS, phoneNumber);
addrValues.put(Telephony.Mms.Addr.TYPE, 137);
// addrValues.put(Telephony.Mms.Addr.TYPE, PduHeaders.TO);
Uri insertedAddrUri = this.context.getApplicationContext().getContentResolver().insert(addrUri, addrValues);
// // 3. add text part
Uri partUri = Uri.withAppendedPath(mmsUri, "part");
ContentValues partValues = new ContentValues();
partValues.put(Telephony.Mms.Part.MSG_ID, messageId);
partValues.put(Telephony.Mms.Part.CONTENT_TYPE, "text/plain");
partValues.put(Telephony.Mms.Part.TEXT, msg);
Uri insertedPartUri = context.getApplicationContext().getContentResolver().insert(partUri, partValues);
smsManager.sendMultimediaMessage(this.context.getApplicationContext(), mmsUri, null, null, null);
} catch (Exception ex) {
System.out.println("couldn't send message.");
}
}
Whenever I attempt to send the MMS, no error messages appear, but when I check the default messaging app, the MMS is not sent.