如何在Android中ListThings AWS IOT

时间:2017-10-26 15:38:26

标签: android amazon-web-services aws-sdk aws-iot

这是代码段:

private  AWSIotClient awsIotClient;

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

 if (sAWSCredentials == null) {
            sAWSCredentials = new BasicAWSCredentials(AWS_ACCESS_KEY_ID, AWS_SECRET_KEY);
        }

        awsIotClient = new AWSIotClient(sAWSCredentials);
      //  awsIotClient.setEndpoint(iotDataEndpoint);
        Region region = Region.getRegion(MY_REGION);
        awsIotClient.setRegion(region);

getThings() ;

}

 public void getThings() {
          GetThingsList getThingsList = new GetThingsList();
        getThingsList.execute();

}
     private  class GetThingsList extends AsyncTask<Void, Void, AsyncTaskResult<String>> {
    @Override
    protected AsyncTaskResult<String> doInBackground(Void... voids) {
        try {
            ListThingsRequest thingList = new ListThingsRequest();
            thingList.withAttributeName("type");
            awsIotClient.setEndpoint(CUSTOMER_SPECIFIC_ENDPOINT);
            ListThingsResult thingsResult = awsIotClient.listThings(thingList);
            Log.v(TAG, "listThings " + thingsResult);
            return new AsyncTaskResult<String>(thingsResult.toString());
        } catch (Exception e) {
            Log.e("E", "getThingTask", e);
            return new AsyncTaskResult<String>(e);
        }
    }
    @Override
    protected void onPostExecute(AsyncTaskResult<String> result) {
        if (result.getError() == null) {
            Log.i(GetShadowTask.class.getCanonicalName(), result.getResult());
        } else {
            Log.e(GetShadowTask.class.getCanonicalName(), "getThingTask", result.getError());
        }
    }
}

事情的清单仍然是空的。有没有办法获得列表的东西?使用了AWSIoTClient listThings方法,如代码片段所示。如果任何人都可以提供示例代码,将会很有帮助。

0 个答案:

没有答案