前面讲的发送短信就这样吧。能发就行了。不考虑啥性能效率的问题的话,就一个for循环就群发了。至于我想象当中的定制的消息的话,就是获取联系人,匹配短信模版,正则替换得到定制的独一无二的短信。现在就是要获取联系人。最简单的方法就是如下
public class SimpleContact extends ListActivity |
原以为想到,直接将显示的每一个item小的那个字段直接搞成电话号码就行了。现在看来我为啥会那样想呢。。自己手机里的一个联系人有2个电话也是常有的事情啊,那得现实哪个?所以报错啊之类就很正常了。
看看query方法的签名:
public final Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) |
API如下解释
Query the given URI, returning a Cursor over the result set.
For best performance, the caller should follow these guidelines:
Provide an explicit projection, to prevent reading data from storage that aren’t going to be used.
Use question mark parameter markers such as ‘phone=?’ instead of explicit values in the selection parameter, so that queries that differ only by those values will be recognized as the same for caching purposes.
Parameters
uri : The URI, using the content:// scheme, for the content to retrieve.
projection A list of which columns to return. Passing null will return all columns, which is inefficient.
selection A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given URI.
selectionArgs You may include ?s in selection, which will be replaced by the values from selectionArgs, in the order that they appear in the selection. The values will be bound as Strings.
sortOrder How to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort order, which may be unordered.
Returns
A Cursor object, which is positioned before the first entry, or null
看来我的直接通过那样来获取每个联系人姓名及其手机号码的梦想是泡汤了。还得这样做才行。
public void getContact(){ |
若只想要得到手机号码,在第3个参数上面也说了,加where条件即可。
Cursor phones = mContext.getContentResolver().query( |