overview package class tree deprecated index help com.samsung.android.sdk.accessory class samessage java.lang.object com.samsung.android.sdk.accessory.samessage public abstract class samessage extends java.lang.object samessage represents an instance for a message service between a service provider and a service consumer. developer guides both service provider and service consumer application must declare a subclass of saagent and implement the actions of an accessory peer agent. the message service is a kind of representative for the simple dialogue between the two saagent objects. both service provider and service consumer application must create an instance of samessage, and implement the message callbacks: onreceive(sapeeragent, byte[]), onsent(sapeeragent, int) and onerror(sapeeragent, int, int) in order to send a message from an accessory agent and receive a message from remote accessory peer agent. the application must also define a broadcast receiver for the action_accessory_message_received action on the receiver side for the message to be received. the application can call send(sapeeragent, byte[]) to deliver the message to a specific remote accessory peer agent. it can also call securesend(sapeeragent, byte[]) to deliver the message to a specific remote accessory peer agent with encryption enabled. note: an samessage instance will be associated with only one saagent and it should be created on start of the saagent service i.e in yoursubclassextendssaagent().oncreate() callback as follows: public yoursubclassextendssaagent() extends saagent { samessage mmessage; @override public void oncreate() { super.oncreate(); ... mmessage = new samessage(yoursubclassextendssaagent.this){ @override protected void onsent(sapeeragent peeragent, int id) { } @override protected void onerror(sapeeragent peeragent, int id, int errorcode) { } @override protected void onreceive(sapeeragent peeragent, byte[] message) { } }; } } when you build your application in release mode, you must add -keep lines in the proguard.cfg file of your application, to prevent proguard from renaming your subclasses of samessage, sasocket, and saagent. proguard is a tool integrated into the android build system that obfuscates the code by renaming classes and methods. for more information about how to configure proguard, please visit the proguard page of android development site. field summary fields modifier and type field and description static java.lang.string action_accessory_message_disabled broadcast action: indicates the message service has been disabled. static java.lang.string action_accessory_message_enabled broadcast action: indicates the message service has been enabled. static java.lang.string action_accessory_message_received broadcast action: indicates an incoming message from the remote accessory peer agent has been received. static int error_peer_agent_no_response the remote accessory peer agent does not give any response within the timeout period which depends on samsung accessory service framework. static int error_peer_agent_not_supported the remote accessory peer agent does not support message service feature. static int error_peer_agent_unreachable the remote accessory peer agent is not reachable or not alive to receive any messages. static int error_peer_service_not_supported samsung accessory service framework on the remote device does not support message service feature. static int error_service_not_supported samsung accessory service framework on this device does not support message service feature. static int error_unknown the remote accessory peer agent has some internal error which occurred on the remote device. constructor summary constructors constructor and description samessage(saagent agent) creates an samessage instance with the specified saagent. method summary all methods instance methods abstract methods concrete methods modifier and type method and description protected abstract void onerror(sapeeragent peeragent, int id, int errorcode) called when the message cannot be sent or is not delivered to the remote accessory peer agent. protected abstract void onreceive(sapeeragent peeragent, byte[] message) called when a message is received from a remote accessory peer agent. protected abstract void onsent(sapeeragent peeragent, int id) called when the message is successfully delivered to the remote accessory peer agent. int securesend(sapeeragent peeragent, byte[] message) same like send(sapeeragent, byte[]) but the message will be encrypted internally. int send(sapeeragent peeragent, byte[] message) send a message to a remote accessory peer agent. field detail error_peer_agent_unreachable public static final int error_peer_agent_unreachable the remote accessory peer agent is not reachable or not alive to receive any messages. constant value: 1793 (0x00000701) since: 2.5.0 see also: onerror(sapeeragent, int, int), constant field values error_peer_agent_no_response public static final int error_peer_agent_no_response the remote accessory peer agent does not give any response within the timeout period which depends on samsung accessory service framework. constant value: 1794 (0x00000702) since: 2.5.0 see also: onerror(sapeeragent, int, int), constant field values error_peer_agent_not_supported public static final int error_peer_agent_not_supported the remote accessory peer agent does not support message service feature. it needs to establish legacy service connection. constant value: 1795 (0x00000703) since: 2.5.0 see also: onerror(sapeeragent, int, int), constant field values error_peer_service_not_supported public static final int error_peer_service_not_supported samsung accessory service framework on the remote device does not support message service feature. it needs to establish legacy service connection. constant value: 1796 (0x00000704) since: 2.5.0 see also: onerror(sapeeragent, int, int), constant field values error_service_not_supported public static final int error_service_not_supported samsung accessory service framework on this device does not support message service feature. it needs to establish legacy service connection. constant value: 1797 (0x00000705) since: 2.5.0 see also: onerror(sapeeragent, int, int), constant field values error_unknown public static final int error_unknown the remote accessory peer agent has some internal error which occurred on the remote device. constant value: 1798 (0x00000706) since: 2.5.0 see also: onerror(sapeeragent, int, int), constant field values action_accessory_message_enabled public static final java.lang.string action_accessory_message_enabled broadcast action: indicates the message service has been enabled. constant value: "com.samsung.accessory.action.message_enabled" since: 2.5.0 see also: constant field values action_accessory_message_disabled public static final java.lang.string action_accessory_message_disabled broadcast action: indicates the message service has been disabled. constant value: "com.samsung.accessory.action.message_disabled" since: 2.5.0 see also: constant field values action_accessory_message_received public static final java.lang.string action_accessory_message_received broadcast action: indicates an incoming message from the remote accessory peer agent has been received. note: the broadcast receiver must be registered in the receiving application's manifest constant value: "com.samsung.accessory.action.message_received" since: 2.5.0 see also: constant field values constructor detail samessage public samessage(saagent agent) creates an samessage instance with the specified saagent. parameters: agent - the subclass that extends saagent base class. since: 2.5.0 method detail send public int send(sapeeragent peeragent, byte[] message) throws java.io.ioexception send a message to a remote accessory peer agent. to find a matching accessory peer agent, please use saagent.findpeeragents(). sender will receive the delivery status via onsent(sapeeragent peeragent, int id) or onerror(sapeeragent peeragent, int id, int errorcode) callback. the message will be delivered to the remote accessory peer agent through its onreceive(sapeeragent, byte[]) callback in its samessage implementation. note: this method is a blocking call hence do not invoke this method on the main thread of the application. it is recommended to use a separate thread to invoke this api. do not send a byte array bigger than sapeeragent.getmaxallowedmessagesize(). only one thread can send a message to one accessory peer agent at a time. parameters: peeragent - the remote accessory peer agent to receive the message. message - the byte array of the message to be sent. returns: id of sending a message. throws: java.io.ioexception - thrown if an i/o-related error occurs while sending a message. java.lang.illegalargumentexception - thrown if any arguments is invalid. since: 2.5.0 see also: onreceive(sapeeragent, byte[]), onsent(sapeeragent, int), onerror(sapeeragent, int, int) securesend public int securesend(sapeeragent peeragent, byte[] message) throws java.io.ioexception same like send(sapeeragent, byte[]) but the message will be encrypted internally. to find a matching accessory peer agent, please use saagent.findpeeragents(). sender will receive the delivery status via onsent(sapeeragent peeragent, int id) or onerror(sapeeragent peeragent, int id, int errorcode) callback. the message will be delivered to the remote accessory peer agent through its onreceive(sapeeragent, byte[]) callback in its samessage implementation. note: this method is a blocking call hence do not invoke this method on the main thread of the application. it is recommended to use a separate thread to invoke this api. do not send a byte array bigger than sapeeragent.getmaxallowedmessagesize(). only one thread can send a message to one accessory peer agent at a time. parameters: peeragent - the remote accessory peer agent to receive the message. message - the byte array of the message to be sent. returns: id of sending a message. throws: java.io.ioexception - thrown if an i/o-related error occurs while sending message. java.lang.illegalargumentexception - thrown if any argument is invalid. since: 2.5.0 see also: onreceive(sapeeragent, byte[]), onsent(sapeeragent, int), onerror(sapeeragent, int, int) onreceive protected abstract void onreceive(sapeeragent peeragent, byte[] message) called when a message is received from a remote accessory peer agent. parameters: peeragent - the remote accessory peer agent who has sent the message. message - the byte[] message since: 2.5.0 onsent protected abstract void onsent(sapeeragent peeragent, int id) called when the message is successfully delivered to the remote accessory peer agent. parameters: peeragent - the remote accessory peer agent to receive the message. id - id of sending a message. it matches with the returned value in send(sapeeragent, byte[]) or securesend(sapeeragent, byte[]). since: 2.5.0 onerror protected abstract void onerror(sapeeragent peeragent, int id, int errorcode) called when the message cannot be sent or is not delivered to the remote accessory peer agent. parameters: peeragent - the remote accessory peer agent to receive the message. id - id of sending a message. it matches with the returned value in send(sapeeragent, byte[]) or securesend(sapeeragent, byte[]). -1 if message service feature is not supported between the accessory agent and the accessory peer agent. errorcode - the error code corresponding to error_*. since: 2.5.0 see also: error_peer_agent_unreachable, error_peer_agent_no_response, error_peer_agent_not_supported, error_peer_service_not_supported, error_service_not_supported, error_unknown