ServiceRecordGetPrimaryMultiLanguageStringAttributeById Method

Gets a String containing the value of the TextString service attribute with the specified ID, using the primary natural language.

Definition

Namespace: InTheHand.Net.Bluetooth.Sdp
Assembly: InTheHand.Net.Bluetooth (in InTheHand.Net.Bluetooth.dll) Version: 4.0.32+5cdf1cfd21064ea31c5de33d160200ca1c4bc218
C#
public string GetPrimaryMultiLanguageStringAttributeById(
	ServiceAttributeId id
)

Parameters

id  ServiceAttributeId
The id of the service attribute to locate, as a ServiceAttributeId.

Return Value

String

[Missing <returns> documentation for "M:InTheHand.Net.Bluetooth.Sdp.ServiceRecord.GetPrimaryMultiLanguageStringAttributeById(InTheHand.Net.Bluetooth.AttributeIds.ServiceAttributeId)"]

Remarks

As noted in the documentation on this class, string are defined in an odd manner, and the multi-language strings defined in the base SDP specification are defined in a very very odd manner. The natural language and the string’s encoding are not included in the element, but instead are defined in a separate element, and the ID of the string attribute is modified. This pair is present for each natural language.

This method is provided to simplify accessing those strings, it will find the primary Language attribute and use it to find and decode the string. And if there is no primary Language attribute, which is the case in many of the records one sees on mobile phones, it will attempt the operation assuming the string is encoded in UTF-8 (or ASCII).

Example

C#:
C#
try {
  String sn = record.GetMultiLanguageStringAttributeById(UniversalAttributeId.ServiceName);
  Console.WriteLine("ServiceName: " + sn);
} catch (KeyNotFoundException) {
  Console.WriteLine("The record has no ServiceName Attribute.");
}

Exceptions

KeyNotFoundException There is no attribute with the given Id in the record. Throws ArgumentException in NETCFv1
InvalidOperationException The service element is not of type TextString.
DecoderFallbackException If the value in the service element is not a valid string in the encoding specified in the given LanguageBaseItem.

See Also