我编写了一个自动短信响应器:
.
.
.
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
.
.
.
答案 0 :(得分:4)
我有一个解决方案(在pskink的帮助下):
.
.
.
procedure FetchSMS; //fetch sms used by timer every 1 minute
var
cursor: JCursor;
uri: Jnet_Uri;
uri_del: Jnet_Uri;
id_smsid: integer;
id_smssender: integer;
id_smsbody: integer;
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');
// ???? Now I need to delete this received message ????
// There is the answer
uri_del:= StrToJURI('content://sms');
SharedActivity.getContentResolver.delete(uri_del, StringToJString('_ID=' + smsid), nil);
// There is the answer
end
else
Break;
end;
end;
。 。