1
我试图查询活动外的联系人内容提供者。但managedQuery是Activity的一种方法。有没有其他的类/方法可以用来代替managedQuery?如何查询活动外的联系人内容提供者?
这里是我的代码:
class MyActivity extends Activity {
private Cursor getContacts() {
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] { ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.HAS_PHONE_NUMBER };
String where = null;
String[] whereArgs = null;
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
+ " COLLATE LOCALIZED ASC";
return context.managedQuery(uri, projection, where, whereArgs, sortOrder);
}
}
这将不得不意味着我的类仍然需要从Context继承吗? – javauser 2010-10-10 00:10:07
不,但您需要从某处获得有效的上下文(也可能是服务)。您希望运行查询的使用场景是什么? – Thorstenvv 2010-10-11 15:58:08
如何从“哪里”获得有效的上下文?例如,在Utils类中定义的静态函数 – matteo 2012-02-16 21:23:11