0

I am new to integrate the cumulocity SDK with android program. I want to try cumulocity example like below code.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final TextView mTextView = (TextView) findViewById(R.id.text1);
    new AsyncTask<Object, Object, Object>() {
        @Override
        protected Object doInBackground(Object... arg0) {
            Log.i("Richard debug","richard 1");
            Platform platform = new PlatformImpl(
                    "https://developer.cumulocity.com", "<teanant id>", "<user>",
                    "<password>","<unknow>");
            Log.i("Richard debug","richard 2");
            InventoryApi inventory = platform.getInventoryApi();
            Log.i("Richard debug","richard 3");
            ManagedObjectRepresentation mo = new ManagedObjectRepresentation();
            Log.i("Richard debug","richard 4");
            mo.setName("Hello, Android!");
            Log.i("Richard debug","richard 5");
            mo = inventory.create(mo);
            Log.i("Richard debug","URL: " + mo.getSelf());
            return null;
        }
    }.execute();
}

}

When i run "inventory.create(mo);" The server always return. //Log

"Caused by: com.cumulocity.android.sdk.SDKException: The server returned 401: Unauthorized! "

I think the problem maybe in this function.

platform = new PlatformImpl(host, port, tenantId, user, password, applicationKey);

I don't know what's the "applicationKey" in this function. So i use the "" in the parameter.

Is there have any one familiar cumulocity android sdk? Or any other way to developing the android program with cumulocity server?

連世鈺
  • 1
  • 4
  • The application key is used to identify the application that is making the call. You create applications using "Own applications" in the administration app and set the application key there. You could for test purposes simply try to set the parameter to "devicemanagement-application-key" (in which case it looks like device management would be making the call). – André Apr 07 '17 at 13:40

1 Answers1

0

I found cumulocity provide a more convenient way to get data from server. I try the rest api on android and use android volley library to get data. I solve my problem to develope app on android.

連世鈺
  • 1
  • 4