In Xamarin.Android, I have setup a custom ContentProvider
that serves the PDU file to the system when sending an MMS:
[ContentProvider(new[] { Authority }, GrantUriPermissions = true)]
internal class MmsUploadContentProvider : ContentProvider
{
internal const string Authority = "my.package.name.mmsUploads";
public override ParcelFileDescriptor OpenFile(AndroidUri uri, string mode)
{
File uploadsDirectory = GetMmsUploadsDirectory(this.Context);
File file = new File(uploadsDirectory, uri.LastPathSegment);
ParcelFileDescriptor result = ParcelFileDescriptor.Open(file, ParcelFileMode.ReadOnly);
return result;
}
}
I call SendMultimediaMessage
like so:
Uri contentProviderUri = Uri.Parse($"content://{MmsUploadContentProvider.Authority}/{pduFileName}");
smsManager.SendMultimediaMessage(this.Context, contentProviderUri, null, null, statusPendingIntent);
However, when my BroadcastReceiver
is called with the result of the request, it receives a MMS_ERROR_IO_ERROR result code. In the documentation, it talks about an issue reading the PDU, so I assume there is something wrong with my ContentProvider
. When I debug, OpenFile
gets called in my ContentProvider
, and a proper ParcelFileDescriptor
gets returned just fine.
Could someone point me in the right direction to fix this? It used to work some years ago, but something must have changed in the Android APIs, causing this to break.