更新时间:2019-11-20
描述
用户可以更改自己的头像。使用的头像可以是系统头像也可以是自定义头像也可以获取头像,在获取头像时服务器会推送获取头像的回调消息给用户,从服务器上得到指定联系人的头像信息。
前提条件
已完成组件的初始化和登录。
业务流程
代码示例:
1 2 3 4 5 6 7 8 9 10 11 |
//java code TsdkEAddrManager tsdkEAddrManager = TsdkManager.getInstance().geteAddrManager(); public int setSystemIcon(int resId) { int result = tsdkEAddrManager.setSystemIcon(resId); if (result != 0) { Log.e(TAG, "Set user system icon filed, result -->" + result); } return result; } |
代码示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//java code TsdkEAddrManager tsdkEAddrManager = TsdkManager.getInstance().geteAddrManager(); public int setDefinedIcon(String smallIconFilePath, String mediumIconFilePath, String largeIconFilePath) { TsdkIconInfo iconInfo = new TsdkIconInfo(smallIconFilePath, mediumIconFilePath, largeIconFilePath); String result = tsdkEAddrManager.setUserDefIcon(iconInfo); if (null != result) { return 0; } return -1; } |
需要传入的参数为查询的帐户以及序列号。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
//java code TsdkEAddrManager tsdkEAddrManager = TsdkManager.getInstance().geteAddrManager(); private int queryContactsIconSeq = 1; private static Map<Integer, String>querySeqAccountMap = new HashMap<>(); public int getUserIcon(String account) { int seq = queryContactsIconSeq++; TsdkGetIconParam iconParam = new TsdkGetIconParam(); iconParam.setSeqNo(seq); iconParam.setAccount(account); querySeqAccountMap.put(seq, account); int result = tsdkEAddrManager.getUserIcon(iconParam); if (result != 0) { Log.e(TAG, "search user icon failed -->" + result); } return seq; } |
查询头像的结果信息包括操作结果,查询序号,系统头像ID(用户设置的是系统头像)或者自定义头像文件路径(用户设置的是自定义头像)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
//Java code public void handleGetIconResult(int querySeqNo, TsdkCommonResult result, TsdkGetIconResult getIconResult) { int ret = result.getResult(); int seqNo = querySeqNo; String account = querySeqAccountMap.get(seqNo); if (ret == 0) { int sysId = getIconResult.getIconId(); String avatarFile = getIconResult.getIconPath(); if (querySelfIconSeq == seqNo) { EntAddressBookIconInfo selfIcon = new EntAddressBookIconInfo(); selfIcon.setAccount(account); selfIcon.setIconFile(avatarFile); selfIcon.setIconId(sysId); selfIcon.setIconSeq(seqNo); notification.onEntAddressBookIconNotify(EntAddressBookConstant.Event.GET_SELF_ICON, selfIcon); } else if (sysId >= 0 && avatarFile.isEmpty()) { EntAddressBookIconInfo iconInfo = new EntAddressBookIconInfo(); iconInfo.setAccount(account); iconInfo.setIconId(sysId); iconInfo.setIconSeq(seqNo); notification.onEntAddressBookIconNotify(EntAddressBookConstant.Event.GET_CONTACTS_SYSTEM_ICON, iconInfo); } else { EntAddressBookIconInfo iconInfo = new EntAddressBookIconInfo(); iconInfo.setAccount(account); iconInfo.setIconFile(avatarFile); iconInfo.setIconSeq(seqNo); notification.onEntAddressBookIconNotify(EntAddressBookConstant.Event.GET_CONTACTS_CUSTOM_ICON, iconInfo); } Log.i(TAG, sysId + "System Avatar ID " + avatarFile + "Custom Avatar filename"); } else { EntAddressBookIconInfo iconInfo = new EntAddressBookIconInfo(); iconInfo.setAccount(account); iconInfo.setIconSeq(seqNo); Log.e(TAG, "User get icon failed, result -->" + result); notification.onEntAddressBookIconNotify(EntAddressBookConstant.Event.GET_CONTACTS_ICON_FAILED, iconInfo); } } |
注意事项
无。