我正在制作一个连接到亚马逊 AWS 服务的应用程序。我的一切都已正确连接,但在连接之前我需要按一个按钮。有没有办法避免这一步并让它自动连接到AWS?现在,用户必须按下一个按钮表示他们想要连接,然后按下另一个按钮表示他们想要订阅某个主题以接收更新。由于此应用程序的唯一目的是连接到 AWS,因此我想删除按钮按下操作,因为这只是浪费时间。这是我的代码:@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.context = PubSubActivity.this; //Sets up layout information txtSubscribe = (EditText) findViewById(R.id.txtSubscribe); tvClientId = (TextView) findViewById(R.id.tvClientId); tvStatus = (TextView) findViewById(R.id.tvStatus); tvSteamTemp = (TextView) findViewById(R.id.tvSteamTemp); tvWaterTemp = (TextView) findViewById(R.id.tvWaterTemp); tvWaterFlow = (TextView) findViewById(R.id.tvWaterFlow); tvDieselFlow = (TextView) findViewById(R.id.tvDieselFlow); tvManualResetLevel = (TextView) findViewById(R.id.tvManualResetLevel); tvWaterFeederLevel = (TextView) findViewById(R.id.tvWaterFeederLevel); tvAutoResetPressure = (TextView) findViewById(R.id.tvAutoResetPressure); tvManualResetPressure = (TextView) findViewById(R.id.tvManualResetPressure); tvTempLimit = (TextView) findViewById(R.id.tvTempLimit); btnConnect = (Button) findViewById(R.id.btnConnect); btnConnect.setOnClickListener(connectClick); btnConnect.setEnabled(false); btnSubscribe = (Button) findViewById(R.id.btnSubscribe); btnSubscribe.setOnClickListener(subscribeClick); btnDisconnect = (Button) findViewById(R.id.btnDisconnect); btnDisconnect.setOnClickListener(disconnectClick); /* MQTT client IDs are required to be unique per AWS IoT account. * This UUID is "practically unique" but does not _guarantee_ * uniqueness. */ clientId = UUID.randomUUID().toString(); tvClientId.setText(clientId);
添加回答
举报
0/150
提交
取消