我正在使用此代码(如下所示)删除已发送的短信,此代码需要发件人的号码(我的设备号码),但我想使用接收者的号码(我发送短信的号码)删除短信。请告诉我该怎么做?
代码:
public partial class InvoiceForm : Page
{
FixedDocument fixedDoc = new FixedDocument();
PrintDialog prtDialog = new PrintDialog();
bool isPrinted = false;
public InvoiceForm()
{
InitializeComponent();
string dateNow = DateTime.Now.ToString("dd MMM yyyy", new CultureInfo("id-ID"));
HeaderDateNow.Text = DateInfoDateNow.Text = dateNow;
Console.WriteLine(dateNow);
string saved = XamlWriter.Save(ContainerStackPanel);
StringReader sReader = new StringReader(saved);
XmlReader xReader = XmlReader.Create(sReader);
StackPanel containerStackPanelClone = (StackPanel)XamlReader.Load(xReader);
FixedPage fixedPage = new FixedPage();
PageContent pageContent = new PageContent();
FixedDocument fixedDoc = new FixedDocument();
fixedPage.Children.Add(containerStackPanelClone);
fixedPage.Margin = new Thickness(62, 38, 25, 30);
pageContent.Child = fixedPage;
fixedDoc.DocumentPaginator.PageSize = new Size(GetPaperSize(PaperKind.A4).Width * 96,
GetPaperSize(PaperKind.A4).Height * 96);
fixedDoc.Pages.Add(pageContent);
ContainerStackPanel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
ContainerStackPanel.Arrange(new Rect(new Point(0, 0), ContainerStackPanel.DesiredSize));
Console.WriteLine("ContainerStackPanel, Width: {0} Height: {1}", ContainerStackPanel.ActualWidth, ContainerStackPanel.ActualHeight);
Console.WriteLine("fixedDoc, Width: {0} Height: {1}",
fixedDoc.DocumentPaginator.PageSize.Width, fixedDoc.DocumentPaginator.PageSize.Height);
// Print the document
prtDialog.PrintDocument(fixedDoc.DocumentPaginator, "Test Print Form");
}
}
答案 0 :(得分:0)
public void deleteSMS(Context ctx, String message, String number) {
try {
Uri mSmsinboxQueryUri = Uri.parse("content://sms/inbox");
Cursor cursor1 = ctx.getContentResolver().query(mSmsinboxQueryUri,
new String[]{"_id", "thread_id", "address", "person", "date",
"body", "type"}, null, null, null);
((Activity)ctx).startManagingCursor(cursor1);
String[] columns = new String[]{"address", "person", "date", "body", "type"};
if (cursor1.getCount() > 0) {
String count = Integer.toString(cursor1.getCount());
Log.e("Count", count);
while (cursor1.moveToNext()) {
String type = cursor1.getString(cursor1.getColumnIndex(columns[4]));
if (type.equals("2")) // 2 for Sent Sms
{
String address = cursor1.getString(cursor1.getColumnIndex(columns[0]));
String name = cursor1.getString(cursor1.getColumnIndex(columns[1]));
String date = cursor1.getString(cursor1.getColumnIndex(columns[2]));
String body = cursor1.getString(cursor1.getColumnIndex(columns[3]));
if (message.equals(body) && address.equals(number)) {
// mLogger.logInfo("Deleting SMS with id: " + threadId);
int rows = ctx.getContentResolver().delete(Uri.parse("content://sms/" + id), "date=?", new String[]{c.getString(4)});
Log.e("log>>>", "Delete success......... rows: " + rows);
Log.e("log>>>", "Delete success......... body: " + body);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}