有什么方法可以从基于 Android 平台构建的应用程序将预定义消息插入到收件箱中的现有对话中?
使用此代码,我可以检索最后发送和接收的消息。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
Uri uriSMS = Uri.parse("content://sms/");
Cursor cur = getContentResolver().query(uriSMS, null, null, null, null);
cur.moveToNext();
String body = cur.getString(cur.getColumnIndex("body"));
String add = cur.getString(cur.getColumnIndex("address"));
String time = cur.getString(cur.getColumnIndex("date"));
String protocol = cur.getString(cur.getColumnIndex("protocol"));
String contactName = "";
Uri personUri = Uri.withAppendedPath( ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(add));
Cursor c = getContentResolver().query(personUri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null );
if( c.moveToFirst() ) {
int nameIndex = c.getColumnIndex(PhoneLookup.DISPLAY_NAME);
contactName = c.getString(nameIndex);
}
c.close();
cur.close();
String out = "";
Date d = new Date(Long.valueOf(time));
if (protocol == null)
out = "Sending to: "+ contactName + " <"+add +">\nDate: "+d +"\nBody: "+body+"\n\n";
else
out = "Received from: "+ contactName + " <"+add +">\nDate: "+d +"\nBody: "+body+"\n\n";
tv.setText(out);
setContentView(tv);
}
有什么方法可以将它合并到我的广播接收器(SmsReceiver.java)中?希望有一种方法可以触发事件,以便在收到新消息时可以将预定义消息插入与收件箱中最新文本消息相关的对话中。
当我在做的时候。有什么方法可以在不要求用户手动输入的情况下准确地检索本地电话号码?