562935844@qq.com
2023-08-31 fdcf461fbfa3bcd650685743e891ad3357898f0c
HDLSDK_DEMO/app/src/main/java/com/hdl/hdlsdk/MainActivity.java
@@ -2,6 +2,7 @@
import android.Manifest;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
@@ -14,6 +15,7 @@
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@@ -23,9 +25,11 @@
import com.google.gson.reflect.TypeToken;
import com.hdl.hdlsdk.device.DevicesListActivity;
import com.hdl.sdk.common.config.TopicConstant;
import com.hdl.sdk.common.event.DeleteNetworkListener;
import com.hdl.sdk.common.event.EventListener;
import com.hdl.sdk.common.exception.HDLLinkException;
import com.hdl.sdk.common.utils.IdUtils;
import com.hdl.sdk.common.utils.LogUtils;
import com.hdl.sdk.common.utils.gson.GsonConvert;
import com.hdl.sdk.connect.HDLLink;
import com.hdl.sdk.connect.bean.LinkResponse;
@@ -55,10 +59,11 @@
    private RecyclerView rv;
    private TextView tv;
    private TextView responseTv;
    private TextView localSecret;
    private EditText editText;
    boolean isOn;
    private EventListener allTopicsListener;
    private String testLightSid = "0001010D48C71B02020100010101";
    private String testLightSid = "02010131D9C03D01020300010107";
    private String secret = "";
    @Override
@@ -69,19 +74,32 @@
    void initDeviceInfo() {
        AuthenticateRequest.AuthenticateDeviceInfoBean infoBean = new AuthenticateRequest.AuthenticateDeviceInfoBean();
<<<<<<< HEAD
        infoBean.setDeviceMAC("AA00000000000100");
        infoBean.setIPMAC("AA00000000000100");
=======
        infoBean.setDeviceMAC("f2c5d8bad48f");
        infoBean.setIPMAC("f2c5d8bad48f");
>>>>>>> not_androidx
        infoBean.setDeviceName("音乐播放器");//设备名字
        infoBean.setDeviceModel("MCLog.431");//设备型号
        infoBean.setAccessMode("WIFI");
        infoBean.setIPGateway("192.168.1.1");
<<<<<<< HEAD
        infoBean.setIPAddress("192.168.1.116");
        infoBean.setGateway_type("music.standard");
=======
        infoBean.setIPAddress("192.168.1.103");
        infoBean.setGateway_type("screen.touch");
>>>>>>> not_androidx
        infoBean.setHw_version("HW2.0");
        infoBean.setFw_version("Fw1.0");
        infoBean.setOID("010105000000FE11");//每个设备oid都要不一样
        infoBean.setSid("110105000000FE08110100000011");//每个设备的sid都要不一样
<<<<<<< HEAD
=======
        infoBean.setSupplier("JINMAOYUN");
>>>>>>> not_androidx
        HDLLinkConfig.getInstance().setDeviceInfoBean(infoBean);
    }
@@ -141,10 +159,16 @@
//        String secret = "44b360eb74b7ba64";//通过spk和mac提交云端认证后分配的secret
//        正式服务器
<<<<<<< HEAD
        String spkStr = "screen.mirror";//产品spk
        String macStr = "AA00000000000100";//设备唯一MAC地址
        String secret = "e186beeb7974998e";//通过spk和mac提交云端认证后分配的secret
=======
        String spkStr = "screen.touch";//产品spk
//        String macStr = "AA00000000000100";//设备唯一MAC地址
        String macStr = editText.getText().toString();//设备唯一MAC地址
//        String secret = "e186beeb7974998e";//通过spk和mac提交云端认证后分配的secret
>>>>>>> not_androidx
        String mac_key = stringToMD5(stringToMD5(macStr + secret));
        String versionString = "HDL_V1.0.1";//
@@ -164,6 +188,8 @@
        authbean.setSpk(spkStr);
        authbean.setMACKey(mac_key);
        authbean.setRequest(requestBean);
        HDLLinkConfig.getInstance().setAuthBean(authbean);
        //HDLLinkConfig.getInstance().getDeviceInfoBean()这个初始化的时候要先设置好
        AuthenticateRequest request = new AuthenticateRequest(IdUtils.getUUId(), time, HDLLinkConfig.getInstance().getDeviceInfoBean(), authbean);
        HDLLink.getInstance().startAuthenticateRequest(request, new HDLLinkCallBack() {
@@ -174,10 +200,12 @@
                Log.e(TAG, "onError: 认证失败 " + e.getCode());
            }
            @RequiresApi(api = Build.VERSION_CODES.O)
            @Override
            public void onSuccess(String msg) {
                tv.setText("认证成功");
                responseTv.setText(msg.toString());
                localSecret.setText("密钥:" + HDLLinkConfig.getInstance().getLocalSecret());
            }
        });
    }
@@ -207,6 +235,7 @@
        setContentView(R.layout.activity_main);
        responseTv = findViewById(R.id.response_tv);
        editText = findViewById(R.id.edittext);
        localSecret = findViewById(R.id.local_secret);
        tv = findViewById(R.id.state_tv);
        rv = findViewById(R.id.rv);
        rv.setLayoutManager(new LinearLayoutManager(this));
@@ -215,6 +244,17 @@
        checkIfCertified();
        initDeviceInfo();//初始化
        registerAllTopicsListener();
        HDLLink.getInstance().setDeleteNetworkListener(new DeleteNetworkListener() {
            @Override
            public void onSuccess(Object msg) {
                LogUtils.i("setDeleteNetworkListener onSucceed = " + msg);
            }
            @Override
            public void onFailure() {
                LogUtils.i("setDeleteNetworkListener onFailure");
            }
        });
        ActivityResultLauncher<String[]> launcher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
            @Override
@@ -352,6 +392,9 @@
            @Override
            public void onMessage(Object msg) {
                LinkResponse response = (LinkResponse) msg;
                if ("/user/all/custom/gateway/broadcast_reply".equals(response.getTopic())){
                    localSecret.setText("密钥:" + HDLLinkConfig.getInstance().getLocalSecret());
                }
            }
        };
        HDLLink.getInstance().registerAllTopicsListener(allTopicsListener);