⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 servicerecordimpl.java

📁 java se平台蓝牙开发的插件 ,包括源码 根据readme 生成包很多东西可以自己DIY很实用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * where "0050CD00321B" is the Bluetooth address of the device that provided	 * this ServiceRecord, "3" is the RFCOMM server channel mentioned in this	 * ServiceRecord, and there are three optional parameters related to	 * security and master/slave roles. If this method is called on a	 * ServiceRecord returned from LocalDevice.getRecord(), it will return the	 * connection string that a remote device will use to connect to this	 * service.	 * 	 * Parameters: requiredSecurity - determines whether authentication or	 * encryption are required for a connection mustBeMaster - true indicates	 * that this device must play the role of master in connections to this	 * service; false indicates that the local device is willing to be either	 * the master or the slave Returns: a string that can be used to connect to	 * the service or null if the ProtocolDescriptorList in this ServiceRecord	 * is not formatted according to the Bluetooth specification Throws:	 * IllegalArgumentException - if requiredSecurity is not one of the	 * constants NOAUTHENTICATE_NOENCRYPT, AUTHENTICATE_NOENCRYPT, or	 * AUTHENTICATE_ENCRYPT See Also: NOAUTHENTICATE_NOENCRYPT,	 * AUTHENTICATE_NOENCRYPT, AUTHENTICATE_ENCRYPT	 */	public String getConnectionURL(int requiredSecurity, boolean mustBeMaster) {		/*		 * get RFCOMM port		 */		int port = -1;		DataElement d1 = getAttributeValue(ProtocolDescriptorList);		if (d1.getDataType() == DataElement.DATSEQ)			for (Enumeration e1 = (Enumeration) d1.getValue(); e1					.hasMoreElements();) {				DataElement d2 = (DataElement) e1.nextElement();				if (d2.getDataType() == DataElement.DATSEQ) {					Enumeration e2 = (Enumeration) d2.getValue();					if (e2.hasMoreElements()) {						DataElement d3 = (DataElement) e2.nextElement();						if (e2.hasMoreElements()								&& d3.getDataType() == DataElement.UUID								&& d3.getValue().equals(										UUID.RFCOMM_PROTOCOL_UUID)) {							DataElement d4 = (DataElement) e2.nextElement();							switch (d4.getDataType()) {							case DataElement.U_INT_1:							case DataElement.U_INT_2:							case DataElement.U_INT_4:							case DataElement.INT_1:							case DataElement.INT_2:							case DataElement.INT_4:							case DataElement.INT_8:								port = (int) d4.getLong();								break;							}						}					}				}			}		if (port == -1)			return null;		/*		 * build URL		 */		StringBuffer buf = new StringBuffer("btspp://");		if (device == null)			try {				buf.append(LocalDevice.getLocalDevice().getBluetoothAddress());			} catch (BluetoothStateException bse) {				buf.append("localhost");			}		else			buf.append(getHostDevice().getBluetoothAddress());		buf.append(":");		buf.append(port);		switch (requiredSecurity) {		case NOAUTHENTICATE_NOENCRYPT:			buf.append(";authenticate=false;encrypt=false");			break;		case AUTHENTICATE_NOENCRYPT:			buf.append(";authenticate=true;encrypt=false");			break;		case AUTHENTICATE_ENCRYPT:			buf.append(";authenticate=true;encrypt=true");			break;		default:			throw new IllegalArgumentException();		}		if (mustBeMaster)			buf.append(";master=true");		return buf.toString();	}	/*	 * Used by a server application to indicate the major service class bits	 * that should be activated in the server's DeviceClass when this	 * ServiceRecord is added to the SDDB. When client devices do device	 * discovery, the server's DeviceClass is provided as one of the arguments	 * of the deviceDiscovered method of the DiscoveryListener interface. Client	 * devices can consult the DeviceClass of the server device to get a general	 * idea of the kind of device this is (e.g., phone, PDA, or PC) and the	 * major service classes it offers (e.g., rendering, telephony, or	 * information). A server application should use the setDeviceServiceClasses	 * method to describe its service in terms of the major service classes.	 * This allows clients to obtain a DeviceClass for the server that	 * accurately describes all of the services being offered. When	 * acceptAndOpen() is invoked for the first time on the notifier associated	 * with this ServiceRecord, the classes argument from the	 * setDeviceServiceClasses method is OR'ed with the current setting of the	 * major service class bits of the local device. The OR operation	 * potentially activates additional bits. These bits may be retrieved by	 * calling getDeviceClass() on the LocalDevice object. Likewise, a call to	 * LocalDevice.updateRecord() will cause the major service class bits to be	 * OR'ed with the current settings and updated.	 * 	 * The documentation for DeviceClass gives examples of the integers that	 * describe each of the major service classes and provides a URL for the	 * complete list. These integers can be used individually or OR'ed together	 * to describe the appropriate value for classes.	 * 	 * Later, when this ServiceRecord is removed from the SDDB, the	 * implementation will automatically deactivate the device bits that were	 * activated as a result of the call to setDeviceServiceClasses. The only	 * exception to this occurs if there is another ServiceRecord that is in the	 * SDDB and setDeviceServiceClasses has been sent to that other	 * ServiceRecord to request that some of the same bits be activated.	 * 	 * Parameters: classes - an integer whose binary representation indicates	 * the major service class bits that should be activated Throws:	 * IllegalArgumentException - if classes is not an OR of one or more of the	 * major service class integers in the Bluetooth Assigned Numbers document.	 * While Limited Discoverable Mode is included in this list of major service	 * classes, its bit is activated by placing the device in Limited	 * Discoverable Mode (see the GAP specification), so if bit 13 is set this	 * exception will be thrown. RuntimeExceptin - if the ServiceRecord	 * receiving the message was obtained from a remote device	 */	public void setDeviceServiceClasses(int classes) {		// TODO not yet implemented	}	/*	 * Modifies this ServiceRecord to contain the service attribute defined by	 * the attribute-value pair (attrID, attrValue). If the attrID does not	 * exist in the ServiceRecord, this attribute-value pair is added to this	 * ServiceRecord object. If the attrID is already in this ServiceRecord, the	 * value of the attribute is changed to attrValue. If attrValue is null, the	 * attribute with the attribute ID of attrID is removed from this	 * ServiceRecord object. If attrValue is null and attrID does not exist in	 * this object, this method will return false. This method makes no	 * modifications to a service record in the SDDB. In order for any changes	 * made by this method to be reflected in the SDDB, a call must be made to	 * the acceptAndOpen() method of the associated notifier to add this	 * ServiceRecord to the SDDB for the first time, or a call must be made to	 * the updateRecord() method of LocalDevice to modify the version of this	 * ServiceRecord that is already in the SDDB.	 * 	 * This method prevents the ServiceRecordHandle from being modified by	 * throwing an IllegalArgumentException.	 * 	 * Parameters: attrID - the service attribute ID attrValue - the DataElement	 * which is the value of the service attribute Returns: true if the service	 * attribute was successfully added, removed, or modified; false if	 * attrValue is null and attrID is not in this object Throws:	 * IllegalArgumentException - if attrID does not represent a 16-bit unsigned	 * integer; if attrID is the value of ServiceRecordHandle (0x0000)	 * RuntimeException - if this method is called on a ServiceRecord that was	 * created by a call to DiscoveryAgent.searchServices()	 */	public boolean setAttributeValue(int attrID, DataElement attrValue) {		/*		 * check this is a local service record		 */		if (device != null)			throw new RuntimeException();		if (attrID < 0x0000 || attrID > 0xffff)			throw new IllegalArgumentException();		if (attrID == ServiceRecordHandle)			throw new IllegalArgumentException();		/*		 * remove, add or modify attribute		 */		if (attrValue == null)			return attributes.remove(new Integer(attrID)) != null;		else {			attributes.put(new Integer(attrID), attrValue);			return true;		}	}	public String toString() {		StringBuffer buf = new StringBuffer("{\n");		for (Enumeration e = attributes.keys(); e.hasMoreElements();) {			Integer i = (Integer) e.nextElement();			buf.append("0x");			buf.append(Integer.toHexString(i.intValue()));			buf.append(":\n");			DataElement d = (DataElement) attributes.get(i);			buf.append(d);			buf.append("\n");		}		buf.append("}");		return buf.toString();	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -