Download the Antares Library for Android by clicking the button below. Save the .jar library to your computer's local storage.
DOWNLOAD
Klik "Mulai Aplikasi Android Studio baru".
Give your app a name.
Define the target SDK.
Define your Activity. We recommend you to choose "Empty Activity".
Name your Activity. We recommend you to choose the default option "MainActivity".
Click on the "Android" section.
Move the layout to "Project".
Copy-Paste the downloaded library jar into app -> libs.
Congratulations! You have inserted the library jar.
Source Code
Data stored in Antares
AndroidManifest.xml
In order to execute the Antares API, we need Internet access and in order to access the Internet on Android, we need to add the following lines to AndroidManifest.xml.
<!--- IMPORTANT!!!!!!! ---><!--- Tambahkan line berikut di AndroidManifest.xml Anda ---><!--- Setelah manifest ---><uses-permission android:name="android.permission.INTERNET" /><!--- Sebelum application --->XMLCopy
activity_main.xml
Modify ALL the contents of activity_main.xml with the following content:
// !!!!------ IMPORTANT ---------!!!!//// Ubah semua code setelah package nama.package.Anda dengan// dengan Code berikutimportandroid.os.Bundle;importandroid.support.v7.app.AppCompatActivity;importandroid.util.Log;importandroid.view.View;importandroid.widget.Button;importandroid.widget.TextView;importorg.json.JSONException;importorg.json.JSONObject;importid.co.telkom.iot.AntaresHTTPAPI;importid.co.telkom.iot.AntaresResponse;publicclassMainActivityextendsAppCompatActivityimplementsAntaresHTTPAPI.OnResponseListener{privateButton btnRefresh;privateTextView txtData;privateString TAG ="ANTARES-API";privateAntaresHTTPAPI antaresAPIHTTP;privateString dataDevice; @OverrideprotectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// --- Inisialisasi UI yang digunakan di aplikasi --- // btnRefresh = (Button) findViewById(R.id.btnRefresh); txtData = (TextView) findViewById(R.id.txtData);// --- Inisialisasi API Antares --- // antaresAPIHTTP =AntaresHTTPAPI.getInstance();antaresAPIHTTP.addListener(this);btnRefresh.setOnClickListener(new View.OnClickListener() { @OverridepublicvoidonClick(View v) {antaresAPIHTTP.getLastDataofDevice("your-access-key","your-application-name","your-device-name"); } }); } @OverridepublicvoidonResponse(AntaresResponse antaresResponse) {// --- Cetak hasil yang didapat dari ANTARES ke System Log --- //Log.d(TAG,antaresResponse.toString());try {JSONObject body =newJSONObject(antaresResponse.getBody()); dataDevice =body.getJSONObject("m2m:cin").getString("con");runOnUiThread(new Runnable() { @Overridepublicvoid run() {txtData.setText(dataDevice); } });Log.d(TAG,dataDevice); } catch (JSONException e) {e.printStackTrace(); } }}
Logcat Results
We can filter the output log results on Android. Please fill in the section as shown below. When the button is clicked, the output results can also be seen in the image below.