automed Android SDK

The automed SDK is now available to be integrated with your Android application. This document will help you understand our automed Android Software Development Kit (SDK) and show you step by step how to use it in your Android application

               


Pre-requisites

  1. Android Studio
  2. Targeting Android version >= 21

We used Java 8 for this library, so go ahead and add the following to your module Build.Gradle:

android {
  ...
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

Step 1:

Download the automed SDK.

Click to download the automed Android SDK


Step 2:

Put your aar file in the libs folder. And let’s take the file name sdk-android.aar as an example.

Put the following code in your Project level build.gradle file:

allprojects {
   repositories {
      jcenter()
      flatDir {
        dirs 'libs'
      }
   }
}

And in the app build.gradle, add the following:

dependencies {
    compile(name:'sdk-android', ext:'aar')
}

Then sync your project and you should be good to go!


Step 3:

Example usage:

public class YourActivity extends AppCompatActivity {
    automed automedObj = new automed();
    
    @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Additional setup 
  }

You can also create an instance of the floating action button (with connect, prime and RFID) with the following:

public class YourActivity extends AppCompatAcitivity {
    @Override
  protected void onCreate(Bundle savedInstanceState) {
    new automedView(this);
    automedView view = findViewById(R.id.view_automed);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
  }
 

The automedView class extends RelativeLayout, so placing it in your activity or fragment is straightforward.


Step 4:

For Android, you must have a device that has a SIM card in order to configure the hotspot. Configuring is different for every device, but it should look something like the following:

  1. Name the hotspot “AutoMed” (with the cases!)
  2. Ensure that the password is 12345678

Step 5:

Get values you need to configure the adapter

What you need in your app:

  1. Token (Authorization)
  2. User ID (the user ID in our automed system)
  3. Farm ID (aka site ID)
  4. Industry type of users farm (can only be “Beef”, “Export Beef”, “Pork”, “Dairy Cattle”, “Dairy Sheep”, “Sheep”)
  5. amID (the medication ID in our automed system)

How to get:

Token: you need to ask the users for their emails and passwords of their automed accounts to login. You can use the HTTP library of your choice, passing the email address and password to your login function:

https://api.automed.io/login

The API will return a JWT token for login. Next call you’ll have to make is for the userID, passing the token as a parameter:

https://api.automed.io/user/me

farmID and industryType: same with userID, you can get them by calling (again passing the token as a parameter):

https://api.automed.io/user/farms/

Note: User might have access to multiple farms. So the json here should be an array contains all farms’ information. You need to store farmID and industryType for each farm so the user can select it later.

amID: Once you get the farmID, you can call /treatments to get the automed treatments:

https://api.automed.io/treatments

Important Note: Your application must have your own medication management system. What you need to do once you get the refTreatment here is to connect your medication with the refTreatment’s medication. The best way to do it is to compare the name (in refTreatment we call it ‘amProduct’). Find the correct amID value in refTreatment for your medication. You will need it to configure the adapter of the automed device.


Step 6:

Configure the adapter of the automed device to make it dose

We have three dose types:

Fixed dose    (The device will do a fixed dose based on the medication that is configured to the adapter)

automed.configureAdapterForFixDose(automedDevice device, int amID, String userID, farmID: String farmID, String industryType)

Manual dose    (The device will do the amount of dose which is input by the user.)

automed.configureAdapterForManualDose(automedDevice device, int amID, String userID, farmID: String farmID, String industryType)

Weight-based dose    (The device will do the dose which is calculated by the weight of animals)

automed.configureAdapterForWeightBasedDose(automedDevice device, int amID, String userID, farmID: String farmID, String industryType)

Important Note: Before configuring the weight-based dose, it is better to set the weight unit to be your preferred one. The default weight unit is ‘lbs’. You can set it by calling this function:

automed.setUnit(unit: "kg")
automed.setUnit(unit: "lbs")

Step 7:

Get the latest treatment record:

LdTreatment treatment = automed.getLatestTreatmentRecord()
treatment.getRefTreatmentsAmId()
treatment.getTrDose()
//you can check the other information of this record

Get all treatment record in the local database:

List<LdTreatment> treatments = automed.getAllTreatmentRecords()
for (LdTreatment treatment : treatments) {
    print(treatment.getRefTreatmentsAmId())
    print(treatment.getTrDose())
    //you can check other information of that treatment
}

Sync records from the automed device. We have a new feature called Set&Forget for the automed device. All treatments the user did without connecting to the app will store in the device itself. You need to call this function to get the records and store them into the local database:

automed.syncRecordsFromDevice(automedDevice);

The above steps should include all functions your app can have to control the automed device. Have fun and enjoy the development!

More Information

There is more information stored in the automed Device object such as MAC address, fwVer(firmware version of the device) and AdapterSettings(adapter settings). You can write your own code to get those value if you need. If you have any question about automed SDK for Android or this tutorial, feel free to contact us at support@automed.io.

 

Related Content

The following links relate to content within this document.

 

Still need help?

Can’t find the answer you’re looking for?
Don’t worry we’re here to help!

Request Support

Send us your question over email.

Phone

Send us your question over email.