Android Android SDK allows you to send/receive messages over satellite and call Somewear APIs when on cell/WiFi.
Sample Repo
https://github.com/somewear-labs/hello-space-android
Install
Add Somewear's Maven Repository to your project build.gradle.
Copy maven {
credentials {
username somewearArtifactsUsername
password somewearArtifactsPassword
}
url "https://somewear-artifacts.appspot.com"
}
Define the credentials in your home gradle directory properties, ~/.gradle/gradle.properties . Somewear will distribute these credentials to you over email.
Copy somewearArtifactsUsername=
somewearArtifactsPassword=
Add the Somewear UI SDK dependency to your app module's build.gradle .
Copy dependencies {
...
implementation ('com.somewearlabs:somewear-ui:x.x.x')
...
}
Initialize the SDK when your application starts up. Your api key is provided to you by Somewear.
Copy public class MyApplication extends Application {
@ Override
public void onCreate () {
super . onCreate ();
// Initialize SomewearUI
SomewearUIProperties properties = new SomewearUIProperties( this ) ;
properties . apiKey = "<API_KEY>" ;
SomewearUI . setup (properties);
}
}
Include our “device pill” in your UI to connect to a Somewear device.
Copy < com . somewearlabs . somewearui . api . SomewearPillView
android : layout_width = "match_parent"
android : layout_height = "wrap_content" />
Send a Message
You can send text messages to Somewear users directly via phone number or email. You can also broadcast messages to your Somewear Workspace.
Copy private SomewearRouter router = SomewearRouter . getInstance ();
private void sendSmsMessage() {
String message = "Hello from space!" ;
MessagePayload payload = MessagePayload . build (message , PhoneNumber . build ( "916-555-1111" ));
router . send (payload);
}
Send a Data Payload
You can send arbitrary byte arrays by sending a DataPayload.
Copy private SomewearRouter router = SomewearRouter . getInstance ();
private void sendBytes() {
String message = "Hello from space!" ;
byte [] data = message . getBytes ( StandardCharsets . UTF_8 );
DataPayload payload = DataPayload . build (data);
router . send (payload);
}
Receive Inbound Payloads / Outbound Updates
You can subscribe to inbound payload events by subscribing to the payload observable.
Copy private CompositeDisposable disposable = new CompositeDisposable() ;
@ Override
protected void onCreate( Bundle savedInstanceState) {
super . onCreate (savedInstanceState);
disposable . addAll (
// Observe payload changes
router . getPayload ()
. observeOn ( AndroidSchedulers . mainThread ())
. subscribe ( this :: didReceivePayload)
);
}
@ Override
protected void onDestroy() {
disposable . clear ();
super . onDestroy ();
}
private void didReceivePayload( DevicePayload payload) {
if (payload instanceof MessagePayload) {
MessagePayload messagePayload = (MessagePayload) payload;
Log.d("MyActivity", "Did receive message: content=" + messagePayload.getContent() + "; id=" + payload.getParcelId() + "; status=" + payload.getStatus() + "; isOutbound=" + payload.isOutbound());
}
else if (payload instanceof DataPayload) {
DataPayload dataPayload = (DataPayload) payload;
String base64Data = Base64 . encodeToString ( dataPayload . getData () , Base64 . DEFAULT );
Log.d("MyActivity", "Did receive data: content=" + base64Data + "; id=" + payload.getParcelId() + "; status=" + payload.getStatus() + "; isOutbound=" + payload.isOutbound());
}
}
Logging
The SDK uses SLF4J-Android for logging. To enable logging, add a SLF4J compatible logging framework, such as Logback :
Copy dependencies {
...
implementation 'com.github.tony19:logback-android:2.0.1'
...
}
Add to src/main/assets/logback.xml
:
Copy < configuration >
< appender name = "logcat" class = "ch.qos.logback.classic.android.LogcatAppender" >
< tagEncoder >
< pattern >%logger{12}</ pattern >
</ tagEncoder >
< encoder >
< pattern >[%-20thread] %msg</ pattern >
</ encoder >
</ appender >
< root level = "DEBUG" >
< appender-ref ref = "logcat" />
</ root >
</ configuration >
Last updated 12 months ago