Code example for BluetoothAdapter

Methods: enable, getName, isEnabled, setName

0
		if (mBlueTooth == null) {
			LogUtil.logOnlyDebuggable(TAG, "此手机不支持蓝牙 ");
			return false; 
		} 
		try { 
			if (mBlueTooth.isEnabled()) {
				mIsOriginalEable = true;
				LogUtil.logOnlyDebuggable(TAG, mBlueTooth.getName());
			} else { 
				if (!mBlueTooth.enable()) {
					return false; 
				} 
				putBoolean(NFDUtils.BlueToothOpreator, true);
			} 
		} catch (Exception e) {
			LogUtil.logOnlyDebuggable(TAG, e.toString());
			return false; 
		} 
 
		return true; 
	} 
 
	public void openBlueTooth() { 
		mBlueTooth = BluetoothAdapter.getDefaultAdapter();
		if (mBlueTooth == null) {
			LogUtil.logOnlyDebuggable(TAG, "此手机不支持蓝牙 ");
			return; 
		} 
		try { 
			if (mBlueTooth.isEnabled()) {
				LogUtil.logOnlyDebuggable(TAG, mBlueTooth.getName());
			} else { 
				if (!mBlueTooth.enable()) {
					return; 
				} 
				putBoolean(NFDUtils.BlueToothOpreator, true);
			} 
		} catch (Exception e) {
			LogUtil.logOnlyDebuggable(TAG, e.toString());
		} 
	} 
 
	public void restorationBluetoothName() { 
		mBlueTooth = BluetoothAdapter.getDefaultAdapter();
		if (mBlueTooth == null) {
			LogUtil.logOnlyDebuggable(TAG, "此手机不支持蓝牙 ");
			return; 
		} 
		if (mBlueTooth.isEnabled()) {
			String blueToothName = mBlueTooth.getName();
			if (blueToothName != null
					&& (blueToothName.startsWith("$") && blueToothName
							.endsWith("^"))) {
				mBlueTooth.setName(getString(NFDUtils.BlueToothKey,
						blueToothName));
			} 
		} 
	}