mac
2024-05-22 4598b51c90c695c9ccbe5350a84e4a46b9d8e587
app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMPSDKManager.java
@@ -3,6 +3,7 @@
import android.app.Application;
import android.content.Context;
import android.os.Environment;
import android.os.SystemClock;
import android.text.TextUtils;
@@ -92,12 +93,14 @@
    private void removeCallBack() {
        DCUniMPSDK.getInstance().setUniMPOnCloseCallBack(null);
        DCUniMPSDK.getInstance().setOnUniMPEventCallBack(null);
    }
    /**
     * 监听相关回调
     */
    private void registerCallBack() {
        DCUniMPSDK.getInstance();
        //1.设置小程序被关闭事件监听
        DCUniMPSDK.getInstance().setUniMPOnCloseCallBack(new IUniMPOnCloseCallBack() {
            @Override
@@ -114,10 +117,10 @@
                    mCurrentAppId = "";
                }
//                //小程序被关闭了通知给原生
//                BaseEventBus baseEventBus = new BaseEventBus();
//                baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE);
//                EventBus.getDefault().post(baseEventBus);
                //小程序被关闭了通知给原生
                BaseEventBus baseEventBus = new BaseEventBus();
                baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE);
                EventBus.getDefault().post(baseEventBus);
            }
        });
@@ -130,6 +133,8 @@
                HdlLogLogic.print("收到小程序通知    event=" + event);
                //暂时通过这个处理小程序同时多条相同的请求
                if (data == null) {
                    HdlLogLogic.print("收到小程序通知,data数据为null。", true);
                    return;
                }
//                String key= MD5Utils.getMd5(event+data.toString());
@@ -150,6 +155,8 @@
                    //除了统一处理,剩余其它特定场景的事件通知
                    if (onOtherUniMPEventCallBack != null) {
                        onOtherUniMPEventCallBack.onOtherUniMPEventReceive(appid, event, data, callback);
                    } else {
                        HdlLogLogic.print("收到小程序通知,回调事件为null,无法回调事件并执行业务逻辑--->event=" + event + "\r\n" + "data=" + data, true);
                    }
                }
            }
@@ -273,14 +280,22 @@
                UniMPOpenConfiguration uniMPOpenConfiguration = new UniMPOpenConfiguration();
                uniMPOpenConfiguration.path = path;
                uniMPOpenConfiguration.extraData = jsonObject;
                uniMPOpenConfiguration.splashClass=MySplashView.class;
                uniMP = DCUniMPSDK.getInstance().openUniMP(mContext, uniAppId, uniMPOpenConfiguration);
            }
            //android14有些设备有问题,需要等待
            if (android.os.Build.VERSION.SDK_INT >= 34) {
                if (TextUtils.isEmpty(mCurrentAppId)) {
                    //第一次用要休眠
                    SystemClock.sleep(1000);
                }
            }
            mCurrentAppId = uniAppId;//记录当前小程序
            mUniMPCaches.put(uniMP.getAppid(), uniMP);
        } catch (Exception e) {
            e.printStackTrace();
            HdlThreadLogic.toast(HDLApp.getInstance(), R.string.uni_open_error);
            initDCUniMPSDK(HDLApp.getInstance());
//            initDCUniMPSDK(HDLApp.getInstance());
            HdlLogLogic.print("打开失败===" + e.getMessage());
        }
    }
@@ -344,20 +359,20 @@
     * 注意:需要提前小程序在运行才可成功
     *
     * @param uniAppId 小程序指定
     * @param event    小程序指定主题
     * @param topic    小程序指定主题
     * @param data     String或JSON
     */
    public void sendUniMPEvent(String uniAppId, String event, Object data) {
    public void sendUniMPEvent(String uniAppId, String topic, Object data) {
        if (mUniMPCaches.containsKey(uniAppId)) {
            if (mUniMPCaches.get(uniAppId) != null) {
                mUniMPCaches.get(uniAppId).sendUniMPEvent(event, data);
                HdlLogLogic.print("发送通知成功:event:" + event + " data:" + new Gson().toJson(data));
                mUniMPCaches.get(uniAppId).sendUniMPEvent(topic, data);
                HdlLogLogic.print("Android--->通知---uni--->主题:" + topic + "--->发送数据:" + new Gson().toJson(data));
            } else {
                HdlLogLogic.print("发送失败,小程序对象为空:" + uniAppId);
                HdlLogLogic.print("Android--->通知---uni--->失败--->小程序对象为空:" + uniAppId);
            }
        } else {
            HdlLogLogic.print("发送失败,找不到对应的小程序:" + uniAppId);
            HdlLogLogic.print("Android--->通知---uni--->失败--->小程序对象为空:" + uniAppId);
        }
    }