更新時間:2019-11-20
描述
用戶可以更改自己的頭像。使用的頭像可以是系統(tǒng)頭像也可以是自定義頭像也可以獲取頭像,在獲取頭像時服務器會推送獲取頭像的回調(diào)消息給用戶,從服務器上得到指定聯(lián)系人的頭像信息。
前提條件
已完成組件的初始化和登錄。
業(yè)務流程
代碼示例:
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; } |
需要傳入的參數(shù)為查詢的帳戶以及序列號。
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; } |
查詢頭像的結果信息包括操作結果,查詢序號,系統(tǒng)頭像ID(用戶設置的是系統(tǒng)頭像)或者自定義頭像文件路徑(用戶設置的是自定義頭像)。
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); } } |
注意事項
無。