我編程的短信自動應答:如何從收件箱中刪除短信?
.
.
.
function IsSMSAnswered(smsid: string): Boolean;
begin
// Code to test if SMS is answered
end;
procedure SendReplySMS(reply_smssender, reply_smsbody: string);
begin
// Code to send reply to smssender
end;
procedure FetchSMS; //fetch sms used by timer every 1 minute
var
cursor: JCursor;
uri: Jnet_Uri;
id_smsid: integer;
id_smssender: integer;
id_smsbody: integer;
id_smsid: string;
smssender: string;
smsbody: string;
smsreply: string;
begin
uri:= StrToJURI('content://sms/inbox');
cursor:= SharedActivity.getContentResolver.query(uri, nil, nil, nil, nil);
id_smsid:= cursor.getColumnIndex(StringToJstring('_id'));
id_smssender:= cursor.getColumnIndex(StringToJstring('address'));
id_smsbody:=cursor.getColumnIndex(StringToJstring('body'));
cursor.moveToLast;
for i:= cursor.getCount downto 1 do
begin
smsid:= :=JStringToString(cursor.getString(id_smsid));
if not IsSMSAnswered(smsid) then
begin
smssender:=JStringToString(cursor.getString(id_smssender));
smsbody:=JStringToString(cursor.getString(id_smssender));
if smsbody = 'abc' then
SendReplySMS(smssender, 'reply abc')
else if smsbody = 'def' then
SendReplySMS(smssender, 'reply def');
end
else
Break;
end;
end;
.
.
.
在這種情況下仍然是所有手機中的數據庫接收短信。
如何處理後從手機數據庫中刪除收到的短信?
.
.
.
if not IsSMSAnswered(smsid) then
begin
smssender:=JStringToString(cursor.getString(id_smssender));
smsbody:=JStringToString(cursor.getString(id_smssender));
if smsbody = 'abc' then
SendReplySMS(smssender, 'reply abc')
else if smsbody = 'def' then
SendReplySMS(smssender, 'reply def');
???? Now do I delete this received message ????
end
.
.
.
此解決方案不適用於Delphi ... – pudnivec74
您可以用非常相似的方式將它們刪除 – pskink
您能告訴我怎麼做嗎? – pudnivec74