| | |
| | | |
| | | import android.Manifest; |
| | | import android.content.Intent; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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 |
| | |
| | | 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() { |
| | |
| | | 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()); |
| | | } |
| | | }); |
| | | } |
| | |
| | | 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)); |
| | |
| | | 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 |
| | |
| | | @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); |