我正在制作一个与电话号码有关的小应用程序。
我的问题是我手机的联系人列表中有一个电话号码。例如:0877777777
我想使用该电话号码打开该联系人信息。
只是为了澄清我说的联系人列表时,我的意思是联系人保存在手机中。
如果有人可以帮助我,我将不胜感激。
该PhoneLookup
API仅用于此目的。
String number = "0877777777";
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String[] projection = new String[]{ PhoneLookup._ID, PhoneLookup.DISPLAY_NAME };
Cursor cur = getContentresolver().query(uri, projection, null, null, null);
if (cur != null) {
while (cur.moveToNext()) {
Long id = cur.getLong(0);
String name = cur.getString(1);
Log.d("My Contacts", "found: " + id + " - " + name);
}
cur.close();
}
更新
要在股票联系人应用中打开联系人的个人资料,您需要先获取联系人的CONTACT_ID
,然后Intent
在外部应用中将其用于:
String number = "0877777777";
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String[] projection = new String[]{ PhoneLookup._ID };
Cursor cur = getContentresolver().query(uri, projection, null, null, null);
// if other contacts have that phone as well, we simply take the first contact found.
if (cur != null && cur.moveToNext()) {
Long id = cur.getLong(0);
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri contactUri = Uri.withAppendedPath(Contacts.CONTENT_URI, String.valueOf(id));
intent.setData(contactUri);
context.startActivity(intent);
cur.close();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句