ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
**集成方式以网易Demo为例。** 1.**初始化SDK** **找到****CrashApplication****.java文件,初始化SDK。** ``` MHSDK.getInstance().init(this," "); ``` 2.**找到****LiveStreamingActivity****.java文件** **实现接口****DefaultBeautyEffectListener****,添加变量****:** ``` private Handler mHandler;     private AlertDialog dialog;     private RelativeLayout beautyContainer;     private MHBeautyManager mhBeautyManager;     private BaseBeautyViewHolder beautyViewHolder;     private boolean isResume;     private int retryCount;     private Thread beautyThread; ``` **添加方法:** ``` private void initBeautyView() {         beautyContainer = findViewById(R.id.beauty_view_container);         mHandler = new Handler(getMainLooper());         if (MHSDK.getInstance().isVerEnd()) {             setBeautyView();         } else {             if (beautyThread != null) {                 beautyThread.interrupt();                 beautyThread = null;             }             beautyThread = new BeautyThread(this);             beautyThread.start();         }     }     private void setBeautyView() {         LogManager.getInstance().writeData("MainActivity_setBeautyView_SDKVersion=" + MHSDK.getInstance().getVer());         if (!MHSDK.getInstance().isVerifyAccess()) {             if (retryCount < 10) {                 showRetryDialog();             } else {                 showExitDialog();                 return;             }         }         if (beautyViewHolder != null) {             beautyViewHolder.release();             beautyViewHolder = null;         }         beautyViewHolder = BeautyViewHolderFactory.getBeautyViewHolder(getApplicationContext(), beautyContainer);         beautyViewHolder.show();         beautyViewHolder.setEffectListener(this);         beautyViewHolder.setVisibleListener(visible -> {             if (!visible) {                 beautyViewHolder.show();             }         });         beautyViewHolder.setMhBeautyManager(mhBeautyManager);     }     private void showRetryDialog() {         if (dialog != null) {             dialog.cancel();         }         SDKDialogListener diaLogListener = new SDKDialogListener(this);         dialog = new AlertDialog.Builder(this)                 .setTitle("提示")                 .setMessage("资源获取失败,请检查网络")                 .setCancelable(false)                 .setPositiveButton("确定", diaLogListener)                 .create();         dialog.show();     }     private void showExitDialog() {         if (dialog != null) {             dialog.cancel();         }         DiaLogListener diaLogListener = new DiaLogListener(this);         dialog = new AlertDialog.Builder(this)                 .setTitle("提示")                 .setMessage("资源获取失败,请检查网络并退出重试")                 .setCancelable(false)                 .setPositiveButton("确定", diaLogListener)                 .create();         dialog.show();     } @Override     public void onFilterChanged(FilterBean filterBean) {         if (mhBeautyManager == null) {             return;         }         FilterEnum filterEnum = filterBean.getFilterEnum();         if (filterEnum == FilterEnum.PRO_FILTER) {             mhBeautyManager.changeDynamicFilter(filterBean.getmFilterName());         } else {             Bitmap lookupBitmap = BitmapUtil.getFilterBitmap(this,filterEnum);             mhBeautyManager.setFilter(lookupBitmap);         }     }     @Override     public void onMeiBaiChanged(int progress) {         if (mhBeautyManager != null) {             mhBeautyManager.setSkinWhiting(progress);         }     }     @Override     public void onMoPiChanged(int progress) {         if (mhBeautyManager != null) {             mhBeautyManager.setSkinSmooth(progress);         }     }     @Override     public void onFengNenChanged(int progress) {         if (mhBeautyManager != null) {             mhBeautyManager.setSkinTenderness(progress);         }     }     @Override     public void onBeautyOrigin() {         if (mhBeautyManager != null) {             mhBeautyManager.setSkinWhiting(0);             mhBeautyManager.setSkinSmooth(0);             mhBeautyManager.setSkinTenderness(0);         }     }     static class DiaLogListener implements DialogInterface.OnClickListener {         WeakReference activityWeakReference;         DiaLogListener(LiveStreamingActivity activity) {             this.activityWeakReference = new WeakReference<>(activity);         }         @Override         public void onClick(DialogInterface dialog, int which) {             LiveStreamingActivity activity = activityWeakReference.get();             if (activity == null) return;             switch (which) {                 case -1:                     dialog.cancel();                     activity.finish();                     break;                 case -2:                     dialog.cancel();                     break;             }         }     }     static class SDKDialogListener implements DialogInterface.OnClickListener {         WeakReference activityWeakReference;         SDKDialogListener(LiveStreamingActivity activity) {             this.activityWeakReference = new WeakReference<>(activity);         }         @Override         public void onClick(DialogInterface dialog, int which) {             LiveStreamingActivity activity = activityWeakReference.get();             if (activity == null) return;             switch (which) {                 case -1:                     activity.retryCount++;                     MHSDK.getInstance().clearVerNote();                     MHSDK.getInstance().verify("");                     activity.initBeautyView();                     dialog.cancel(); //                    System.exit(0);                     break;                 case -2:                     dialog.cancel();                     break;             }         }     } ```     //由于demo进入应用直接进入美颜界面,为了防止授权校验未完成而一直显示标准版界面,需要等授权校验完成后初始化对应的美颜界面(延迟1秒或者按下面处理) ```     static class BeautyThread extends Thread {         WeakReference mainActivityWeakReference;         BeautyThread(LiveStreamingActivity LiveStreamingActivity) {             this.mainActivityWeakReference = new WeakReference<>(LiveStreamingActivity);         }         @Override         public void run() {             while (mainActivityWeakReference.get() != null && !MHSDK.getInstance().isVerEnd()) {                 if (isInterrupted()) return;                 try {                     Thread.sleep(200);                 } catch (InterruptedException e) {                     e.printStackTrace();                 }             }             LiveStreamingActivity activity = mainActivityWeakReference.get();             if (activity != null) {                 activity.mHandler.post(activity::setBeautyView);             }         }     } ``` **设置变量****mVideoCallback****为****true****。添加美颜处理回调:** ``` public int onVideoCapture(byte[] data, int textureId, int width, int height, int orientation) {     int newTexId = 0;     try {         if (mhBeautyManager == null) {             mhBeautyManager = new MHBeautyManager(getApplicationContext(), true);             mhBeautyManager.setBeautyDataModel(BeautyDataModel.getInstance());             if (beautyViewHolder != null) {                 beautyViewHolder.setMhBeautyManager(mhBeautyManager);             }             return newTexId;         }         newTexId = mhBeautyManager.render4(textureId, width, height);     } catch (Exception e) {         e.printStackTrace();     }     return newTexId; } ``` **在****onCreate****里添加****initBeautyView****方法。**