🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
**1.获取贴纸类别id** 贴纸类别id常量 ~~~ //MHSDK public static final int TIEZHI_BASIC_STICKER = 0;//基础贴纸 public static final int TIEZHI_PRO_STICKER = 1;//高级贴纸 public static final int TIEZHI_BASIC_MASK = 2;//基础面具 public static final int TIEZHI_PRO_MASK = 3;//高级面具 public static final int TIEZHI_GIFT = 4;//道具礼物 public static final int TIEZHI_ACTION = 5;//动作贴纸 ~~~ 方式一:通过MHSDK的getTiezhiIds方法获取 ~~~ int[] tieZhiIds = MHSDK.getTieZhiIds();//自动判断sdk版本 返回能用的贴纸类别id常量数组 ~~~ 方式二:直接通过MHSDK常量获取 ~~~ int tiezhiId = MHSDK.TIEZHI_BASIC_STICKER ~~~ **2.获取相应类别的贴纸列表数据** ~~~ //MHSDK public static void getTieZhiList(final int tieZhiId, final TieZhiListCallback callback) ~~~ | | | | --- | --- | | tieZhiid | 贴纸类别id常量 | |callback|处理贴纸列表数据的回调| ~~~ //MHSDK public interface TieZhiListCallback { void getTieZhiList(String data); //data:贴纸列表数据的json字符串 } ~~~ 实现TieZhiListCallback接口 处理json数据 可以参考mhui的实现方式 ~~~ public class TieZhiBean { private String mName; //贴纸名称 private String mThumb; //贴纸略缩图 private String mResource; //贴纸资源下载地址 ~~~ ~~~ JSONObject obj = JSON.parseObject(data); List<TieZhiBean> list = JSON.parseArray(obj.getString("list"), TieZhiBean.class); ~~~ **3.下载响应的贴纸** 检查贴纸是否下载过 ~~~ //MHSDK接口 public static boolean isTieZhiDownloaded(String name)//name:贴纸名称 ~~~ ~~~ MHSDK.isTieZhiDownloaded(tieZhiName) ; ~~~ 没有下载则下载贴纸 ~~~ //MHSDK接 public static void downloadSticker(String tiezhiName, MHSDK.TieZhiDownloadCallback tieZhiDownloadCallback) public interface TieZhiDownloadCallback { void tieZhiDownload(String tieZhiName, boolean success); } ~~~ | | | | --- | --- | | tiezhiName| 贴纸名称 | |tieZhiDownloadCallback|贴纸下载结果回调| 实现 MHSDK.TieZhiDownloadCallback接口 处理贴纸下载结果 如果下载成功则设置贴纸(实现方式可参考mhui) **4.设置贴纸** 启用贴纸人脸识别 ~~~ //MHBeautyManager接口 //com.meihu.beautylibrary.manager.MHBeautyManager#getUseFaces 获取需要人脸功能的模块人脸使用状态列表 public int[] getUseFaces() // int[0]=0:贴纸关闭人脸 int[0]=1贴纸使用人脸 int[1]=0:美型关闭人脸 int[1]=1 美型使用人脸 2:一键美颜 3:哈哈镜 4:动作 5:美妆 //com.meihu.beautylibrary.manager.MHBeautyManager#setUseFaces 设置某个模块启用关闭人脸识别 public void setUseFaces(int[] useFaces) // useFaces相应模块是否启用人脸 int[0]:贴纸 int[1]:美型 2:一键美颜 3:哈哈镜 4:动作 5:美妆 ~~~ ~~~ //使用方法 参考mhui int[] useFaces = mhBeautyManager.getUseFaces(); useFaces[0] = 1; mhBeautyManager.setUseFaces(useFaces); ~~~ 设置贴纸 ~~~ //com.meihu.beautylibrary.manager.MHBeautyManager#setSticker public void setSticker(final String stickerName,final int action,final boolean show) ~~~ | | | | --- | --- | | stickerName| 贴纸名称 | |action|是否为动作贴纸:0否 1是| |show|是否显示效果| ~~~ //使用方法参考mhui mMhManager.setSticker(tieZhiName,0,true); ~~~