尝试复制 Android 主屏幕联系人快捷方式,但有问题
好的,我正在尝试复制创建联系人快捷方式时放置在主屏幕上的快捷方式,示例如下:
我有一个可用的 QuickContactBadge,单击它会显示 QuickContact 工具栏。然而,我有两件事遇到了麻烦。
一是图片。我尝试使用 这个问题 中的代码(我通过添加来更改它传入联系人 ID 的参数)。然后,我将图像分配给我的 QuickContactBadge,如下所示:
bdg.setImageURI(getPhotoUri(cid));
它肯定会获取图片,但它得到的图片完全错误。如图所示:
如您所见,它为 Domino 返回的图像显然不是 Domino 的徽标。
我正在将我的联系人 ID 从以下代码传递给该函数:
public static String[] ContactsProjection = new String[] {
Contacts._ID,
Contacts.LOOKUP_KEY,
Contacts.DISPLAY_NAME
};
public static Cursor getContacts() {
ContentResolver cr = CoreLib.ContentResolver();
Cursor contacts = cr.query(
ContactsContract.Data.CONTENT_URI,
ContactsProjection,
null, null,
Contacts.TIMES_CONTACTED + " DESC"
);
return contacts;
}
我相信应该为我返回每条记录的正确 ID。是的?
接下来,如何按照快捷方式显示的方式准确缩小或裁剪缩略图?
我有点失望地发现 QuickContactBadge 实际上并没有复制 QuickContact 快捷方式的整个外观和感觉,...而只是充当 QuickContact 卡的调用目标。是否有任何内置方法可以轻松复制完整的联系人快捷方式、调用、图像、文本等,而无需从头开始复制整个内容?
Okay, I'm trying to replicate the shortcuts which get placed on the homescreen when creating a contact shortcut, example shown:
I've got a working QuickContactBadge, which when clicked shows the QuickContact toolbar. However, I have two things I'm having trouble with.
One is the picture. I tried using the code from this question (I altered it by adding a parameter to pass in the contact ID). I then assign the image to my QuickContactBadge as so:
bdg.setImageURI(getPhotoUri(cid));
It definitely gets pictures, but it is getting TOTALLY the wrong picture. As illustrated here:
As you can see, the image it returned for Domino's is clearly NOT the Domino's logo.
I'm getting my contact ID to pass to the function from this code:
public static String[] ContactsProjection = new String[] {
Contacts._ID,
Contacts.LOOKUP_KEY,
Contacts.DISPLAY_NAME
};
public static Cursor getContacts() {
ContentResolver cr = CoreLib.ContentResolver();
Cursor contacts = cr.query(
ContactsContract.Data.CONTENT_URI,
ContactsProjection,
null, null,
Contacts.TIMES_CONTACTED + " DESC"
);
return contacts;
}
Which I believe should be returning me the proper ID for each record. Yes?
Next how do I get exactly the thumbnail shrunk or cropped as the shortcut shows it?
I was a little disappointed to see that the QuickContactBadge doesn't actually replicate the whole look and feel of the QuickContact shortcut, ... but just acts as in invocation target for the QuickContact card. Is there any built in way to easily replicate the contact shortcut in it's entirety, invocation, image, text and all, without needing to reproduce the whole thing from scratch?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊哈!弄清楚如何获得正确的照片。虽然这看起来违反直觉,但在构建字段投影来查询联系人时,字段
Contacts._ID
和ContactsContract.Data.CONTACT_ID
并不是同一件事。ContactsContract.Data.CONTACT_ID
是传入以获取照片的正确 ID。使用这个,一切现在都是金色的。Ah HAH! Figured out how to get the correct photo. While this seems counter-intuitive, when building your field projection to query the contacts, the fields
Contacts._ID
andContactsContract.Data.CONTACT_ID
are not the same thing.ContactsContract.Data.CONTACT_ID
is the correct one to pass in to get the photo. Use this, and everything is now golden.