我正在制作一個連接到亞馬遜 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
提交
取消