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