我想发送短信并在之后删除该消息(在一两个小时内,以便能够检查交付状态)。
这是我用来发送短信的代码:
SmsManager.Default.SendTextMessage(contact.Text, null,
message.Text, null, null);
如何删除邮件?我找到了一个删除短信的代码,如下所示:
ContentResolver.Delete(Android.Net.Uri.Parse("content://sms/" + pid), null, null);
但我不知道如何获得已发送消息的 pid 。
答案 0 :(得分:0)
试试这个
void deletSms(string message, string number)
{
Uri uriSms = Uri.Parse("content://sms/sent");
Android.Database.ICursor c = ContentResolver.Query(uriSms, new string[] {"_id", "thread_id","address",
"person", "date", "body" }, null, null, null);
if (c != null)
{
do
{
long id = c.GetLong(0);
long threadId = c.GetLong(1);
string address = c.GetString(2);
string body = c.GetString(5);
if (message.Equals(body) && address.Equals(number))
{
Log.Info(tag, "Deleting SMS with id: " + threadId);
ContentResolver.Delete(
Uri.Parse("content://sms/" + id), null, null);
}
} while (c.MoveToNext());
}
}