秘密发送短信(我不希望它出现在我的发件箱中)

时间:2016-04-06 12:56:30

标签: android smsmanager

我正在制作一个安全应用程序,用以下代码发送短信:

public static void SendSMS(String message, String number) {
    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(number, null, message, null, null);
}

它完美无缺但我的问题是: 有没有办法从我的发件箱中删除(以编程方式)我的应用程序发送的短信?如果他们检查我的用户的发件箱,我不希望其他用户能够看到它。

非常感谢!

2 个答案:

答案 0 :(得分:-1)

我不确定但尝试以下功能

content //sms

public void deletesms(Context context, String number) {
    try {
        Uri uriSms = Uri.parse("content://sms/outbox");
        Cursor c = context.getContentResolver().query(
                uriSms,
                new String[] { "_id", "thread_id", "address", "person",
                        "date", "body" }, "read=0", null, null);

        if (c != null && c.moveToFirst()) {
            do {
                long id = c.getLong(0);
                long threadId = c.getLong(1);
                String address = c.getString(2);
                String body = c.getString(5);
                String date = c.getString(3);


                if (address.equals(number)) {

                    context.getContentResolver().delete(
                            Uri.parse("content://sms/" + id), "date=?",
                            new String[] { c.getString(4) });
                    Log.e("log", "Delete ");
                }
            } while (c.moveToNext());
        }
    }  catch (Exception e) {
        Log.e("log", e.toString());
    }
    }

许可

<uses-permission android:name="android.permission.WRITE_SMS"> </ uses-permission>
<uses-permission android:name="android.permission.READ_SMS"> </ uses-permission>

答案 1 :(得分:-1)

 public void deleteSMS(Context context, String message, String number) {
try {
    Uri uriSms = Uri.parse("content://sms/outbox");
    Cursor c = context.getContentResolver().query(
            uriSms,
            new String[] { "_id", "thread_id", "address", "person",
                    "date", "body" }, "read=0", null, null);

    if (c != null && c.moveToFirst()) {
        do {
            long id = c.getLong(0);
            long threadId = c.getLong(1);
            String address = c.getString(2);
            String body = c.getString(5);
            String date = c.getString(3);
            Log.e("log>>>",
                    "0>" + c.getString(0) + "1>" + c.getString(1)
                            + "2>" + c.getString(2) + "<-1>"
                            + c.getString(3) + "4>" + c.getString(4)
                            + "5>" + c.getString(5));
            Log.e("log>>>", "date" + c.getString(0));

            if (message.equals(body) && address.equals(number)) {
                // mLogger.logInfo("Deleting SMS with id: " + threadId);
                context.getContentResolver().delete(
                        Uri.parse("content://sms/" + id), "date=?",
                        new String[] { c.getString(4) });
                Log.e("log>>>", "Delete success.........");
            }
        } while (c.moveToNext());
    }
} catch (Exception e) {
    Log.e("log>>>", e.toString());
}}    

干杯!!