我创建了一个应用程序,它是通过短信更换资料我还添加模块,这是锁定你的Android手机也使用短信现在我想添加功能,这是删除你传入的所有那些消息,这是改变您的个人资料或锁定设备。 例如: 现在正在更改配置文件的消息接收我要删除此消息。只有这条消息改变了个人资料。
答案 0 :(得分:0)
创建消息接收器
public class IncomingSms extends BroadcastReceiver {
String SENDER_PHONENUMBER=<FROM WHICH NUMBER YOU ARE SENDING SMS>;
// Get the object of SmsManager
final SmsManager sms = SmsManager.getDefault();
public void onReceive(Context context, Intent intent) {
// Retrieves a map of extended data from the intent.
final Bundle bundle = intent.getExtras();
try {
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdusObj.length; i++) {
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
String phoneNumber = currentMessage.getDisplayOriginatingAddress();
String senderNum = phoneNumber;
String message = currentMessage.getDisplayMessageBody();
if(senderNum.equals(SENDER_PHONENUMBER))
{
//Delete Last SMS
Uri uriSMSURI = Uri.parse("content://sms/");
Cursor cur = mContext.getContentResolver().query(uriSMSURI, null, null, null, null);
if (cur.moveToFirst()) {
////Changed to 0 to get Message id instead of Thread id :
String MsgId= cur.getString(0);
context.getContentResolver().delete(Uri.parse("content://sms/" + MsgId), null, null);
}
} // end for loop
} // bundle is null
} catch (Exception e) {
Log.e("SmsReceiver", "Exception smsReceiver" +e);
}
}
}
将<FROM WHICH NUMBER YOU ARE SENDING SMS>
替换为您收到个人资料更改消息的号码