package iot.myandroid.helloworld; import android.content.Context; import android.os.AsyncTask; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import java.io.IOException; import oracle.iot.client.*; import oracle.iot.client.device.*; public class MainActivity extends AppCompatActivity { // Your URN from [2] private static final String URN = "urn:test:helloworld"; // Your attribute name from [3] private static final String GREETING_ATTRIBUTE = "greeting"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new HelloWorld().execute(this); } class HelloWorld extends AsyncTask { protected Void doInBackground(Context... params) { try { // Configuration will come from the trusted asset store, the location and password of which is specified in the trustedassets.properties file // while building the trusted assets file, which is part of app context. DirectlyConnectedDevice dcd = new DirectlyConnectedDevice(params[0]); //Activate the device if it is not activated (so that we can run this code more than once!) if (!dcd.isActivated()) { dcd.activate(URN); } // Set up a virtual device based on our device model DeviceModel dcdModel = dcd.getDeviceModel(URN); VirtualDevice virtualDevice = dcd.createVirtualDevice(dcd.getEndpointId(), dcdModel); // Update an attribute on our virtual device. // This will result in a message being sent to the cloud service with the updated attribute value virtualDevice.set(GREETING_ATTRIBUTE, "Hello, World!"); // Flushes the message with library version 16.2.3 + dcd.close(); // In client versions prior to 16.2.3, we need to sleep to give the background thread time to flush the message before we terminate. Thread.sleep(5000); } catch (IOException dse) { dse.printStackTrace(); System.exit(1); } catch (Exception dse) { dse.printStackTrace(); System.exit(1); } return null; } protected void onPostExecute(Long result) { } } }