我想通过仅询问姓名而不显示我的联系人活动来以编程方式获取联系人的电话号码。
有可能吗?怎么样?
我尝试了以下操作,但即使我在清单
中设置了我的权限,也会收到权限错误class Proxy : public IExtendedInterface
{
public:
Proxy(std::unique_ptr<IInterface> object)
: heldObject(std::move(object))
{}
void invalidate() override
{
heldObject.reset(&nullObject);
}
void someMethod() override
{
heldObject->someMethod();
}
private:
std::unique_ptr<IInterface> heldObject;
static NullObject nullObject;
};
class Object : public IInterface
{
public:
void someMethod() override
{
std::cout << "Called from object";
};
class NullObject : public IInterface
{
public:
void someMethod() override
{
std::cout << "Called from NullObject";
};
};
答案 0 :(得分:0)
如果您的意思是从用户那里获取联系人姓名并在Contacts
数据库中找到一个电话号码,这应该有效:
public List<String> getPhoneNumbersByName(String name) {
List<String> phones = new ArrayList<>();
String[] projection = new String[] { Phone.DISPLAY_NAME, Phone.NUMBER };
Cursor cur = cr.query(Phone.CONTENT_URI, projection, Phone.DISPLAY_NAME + "=?", new String[]{ name }, null);
while (cur != null && cur.moveToNext()) {
phones.add = cur.getString(1);
}
if (cur != null) {
cur.close();
}
return phones;
}
注意:
Sqlite
的“LIKE
”选项来放宽此限制