1. @Override
    public void onFoundDevice(ExtendedBluetoothDevice extendedBluetoothDevice) {
    	//此处是搜索到锁列表页面 选择要添加并且是进入可添加状态的锁进行连接
    	if(extendedBluetoothDevice.isSettingMode())
    		mTTLockAPI.connect(extendedBluetoothDevice);
    }
    
    @Override
    public void onFoundDevice(ExtendedBluetoothDevice extendedBluetoothDevice) {
    	// The list of lock, select the lock withch is in setting mode to connect.
    	if(extendedBluetoothDevice.isSettingMode())
    		mTTLockAPI.connect(extendedBluetoothDevice);
    }
    

  2. @Override
    public void onDeviceConnected(ExtendedBluetoothDevice extendedBluetoothDevice) {
    	//这里判断一下本地是否已经存在相同的锁,只能有一把正常使用的钥匙
    	mTTLockAPI.lockInitialize(extendedBluetoothDevice);
    }
    
    @Override
    public void onDeviceConnected(ExtendedBluetoothDevice extendedBluetoothDevice) {
    	// Judge whether has existed the same lock, only a lock is needed
    	mTTLockAPI.lockInitialize(extendedBluetoothDevice);
    }
    

  3. {{getTexts.android.addlock.tip3}} https://api.sciener.com/v3/lock/initialize

    @Override
    public void onLockInitialize(ExtendedBluetoothDevice extendedBluetoothDevice, final LockData lockData, Error error) {
        if(error == Error.SUCCESS) {
            final String lockDataJson = lockData.toJson();
    
            toast(getString(R.string.words_lock_add_successed_and_init));
    
            new AsyncTask<Void, String, Boolean>() {
    
                @Override
                protected Boolean  doInBackground(Void... params) {
                    Boolean flag = false;
                    String json = ResponseService.lockInit(lockDataJson, lockData.getLockName());
                    try {
                        JSONObject jsonObject = new JSONObject(json);
                        if(jsonObject.has("errcode")) {
                            String errmsg = jsonObject.getString("description");
                            toast(errmsg);
                        } else {
                            Intent intent = new Intent(mContext,MainActivity.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
    
                            flag = true;
                            toast(getString(R.string.words_lock_init_successed));
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                        toast(getString(R.string.words_lock_init_failed) + e.getMessage());
                    }
                    return flag;
                }
    
                @Override
                protected void onPostExecute(Boolean flag) {
    
                }
            }.execute();
        } else {
        //失败
            toast(error.getErrorMsg());
        }
    }
    
    public static String lockInit(String lockData, String lockAlias) {
    	String url = “https://api.sciener.com/v3/lock/ initialize”;
    	HashMap params = new HashMap();
    	params.put("clientId", Config.CLIENT_ID);
    	params.put("accessToken", MyPreference.getStr(MyApplication.mContext, MyPreference.ACCESS_TOKEN));
    	params.put("lockAlias", lockAlias);
    	params.put("lockData", lockData);
    	params.put("date", String.valueOf(System.currentTimeMillis()));
    	return OkHttpRequest.sendPost(url, params);
    }
    
    @Override
    public void onLockInitialize(ExtendedBluetoothDevice extendedBluetoothDevice, final LockData lockData, Error error) {
        if(error == Error.SUCCESS) {
            final String lockDataJson = lockData.toJson();
    
            toast(getString(R.string.words_lock_add_successed_and_init));
    
            new AsyncTask<Void, String, Boolean>() {
    
                @Override
                protected Boolean  doInBackground(Void... params) {
                    Boolean flag = false;
                    String json = ResponseService.lockInit(lockDataJson, lockData.getLockName());
                    try {
                        JSONObject jsonObject = new JSONObject(json);
                        if(jsonObject.has("errcode")) {
                            String errmsg = jsonObject.getString("description");
                            toast(errmsg);
                        } else {
                            Intent intent = new Intent(mContext,MainActivity.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
    
                            flag = true;
                            toast(getString(R.string.words_lock_init_successed));
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                        toast(getString(R.string.words_lock_init_failed) + e.getMessage());
                    }
                    return flag;
                }
    
                @Override
                protected void onPostExecute(Boolean flag) {
    
                }
            }.execute();
        } else {
        //failure
            toast(error.getErrorMsg());
        }
    }
    
    public static String lockInit(String lockData, String lockAlias) {
    	String url = “https://api.sciener.com/v3/lock/ initialize”;
    	HashMap params = new HashMap();
    	params.put("clientId", Config.CLIENT_ID);
    	params.put("accessToken", MyPreference.getStr(MyApplication.mContext, MyPreference.ACCESS_TOKEN));
    	params.put("lockAlias", lockAlias);
    	params.put("lockData", lockData);
    	params.put("date", String.valueOf(System.currentTimeMillis()));
    	return OkHttpRequest.sendPost(url, params);
    }