2017-04-07 20 views
0

我是新来整合cumulocity SDK与android程序。 我想尝试像下面的代码一样的cumulocity例子。用cumulocity SDK测试android程序

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(); 
} 

}

当我运行 “inventory.create(MO);” 服务器总是返回。 //日志

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

我觉得这个问题可能在这个函数中。

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

我不知道这个函数中的“applicationKey”是什么。 所以我在参数中使用“”。

是否有任何一个熟悉的cumulocity android sdk? 或任何其他方式来开发与cumulocity服务器的android程序?

+0

应用程序密钥用于标识正在进行呼叫的应用程序。您可以使用管理应用程序中的“自己的应用程序”创建应用程序,并在此设置应用程序密钥你可以为了测试目的而简单地尝试将参数设置为“devicemanagement-application-key”(在这种情况下,它看起来像设备管理将进行呼叫)。 –

回答

0

我发现cumulocity提供了一种更方便的方式从服务器获取数据。 我尝试在android上的其余API,并使用android排球库来获取数据。 我解决了我的问题,在android上开发应用程序。