|
- private void login(String ip, int port, String username, String password) {
- BVCU_SessionParam param = new BVCU_SessionParam();
- BVCU_ServerParam serverParam = new BVCU_ServerParam();
- serverParam.szClientID = getClientID();
- serverParam.iCmdProtoType = 1;
- serverParam.szServerAddr = ip;
- serverParam.iServerPort = port;
- serverParam.szUserName = username;
- serverParam.szPassword = password;
- serverParam.szUserAgent = "monitor";
- // BVPU_ServerParam bvpuServerParam = new BVPU_ServerParam();
- param.iClientType = BVCU_CLIENT_TYPE.BVCU_CLIENT_TYPE_CU;
- param.iCmdProtoType = serverParam.iCmdProtoType;
- param.iMaxChannelOpenCount = 0;
- param.iServerPort = serverParam.iServerPort;
- param.iTimeOut = 30 * 1000;
- param.szClientID = serverParam.szClientID;
- param.szPassword = serverParam.szPassword;
- param.szServerAddr = serverParam.szServerAddr;
- param.szUserAgent = serverParam.szUserAgent;
- param.szUserName = serverParam.szUserName;
- // bvpuServerParam.szDeviceName = "SDK测试";
- // bvpuServerParam.iMediaDir ^= BVCU_MediaDir.BVCU_MEDIADIR_VIDEOSEND;
- // bvpuServerParam.iMediaDir ^= BVCU_MediaDir.BVCU_MEDIADIR_TALKONLY;
- int loginStatus = BVCU.getSDK().login(param);
- Log.d("登陆状态", "loginStatus:" + loginStatus);
- }
- @TargetApi(Build.VERSION_CODES.LOLLIPOP)
- String getRandomID() {
- ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current();
- int i3 = threadLocalRandom.nextInt(10000, 99999);
- return "CU_" + String.valueOf(i3);
- }
- String getClientID() {
- SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE);
- String ID = sp.getString("client_id", null);
- if (ID == null) {
- ID = getRandomID();
- SharedPreferences.Editor editor = sp.edit();//获得sp编辑器
- editor.putString("client_id", ID);
- editor.commit();//类似于数据库的事务,保证数据同时提交
- }
- return ID;
- }
copycode
进入界面 初始化 BVCU.getSDK().init(getApplicationContext()); 然后直接调用登陆 一直失败 |
|