Mobile phone Bluetooth control relay wireless lock Iot Android source code android development Android WIFI control detailed annotation test stability no bug, android Android

Source: Internet
Author: User

Mobile phone Bluetooth control relay wireless lock Iot Android source code android development Android WIFI control detailed annotation test stability no bug, android Android

I. functions:

1. Connect and disconnect Android WIFI, and save the connection IP address and port.

2. WIFI Control 3 Relays

3.16 sending commands, which can be sent in a single order and multiple messages, separated by commas.

4.16 hexadecimal receipt

If you need special features, you can find me to customize (program source code, custom expert mobile phone: 18910620895 trademanager: chenhao0568 QQ: 345139427 ).

Ii. Source Code:

Log on to Login. java

Package com. example. eeeee; import java. io. inputStream; import java. io. outputStream; import java.net. inetAddress; import java.net. socket; import android. OS. bundle; import android. OS. handler; import android. OS. message; import android. annotation. suppressLint; import android. app. activity; import android. view. view; import android. widget. button; import android. widget. checkBox; import android. widget. editText; import Droid. widget. toast; import android. content. intent; import android. content. sharedPreferences; import android. content. sharedPreferences. editor; @ SuppressLint ("NewApi") public class Login <E, K, V> extends Activity {public static Socket mSocket; public static InputStream ips; public static OutputStream ops; // private final String DEBUG_TAG = "mySocketAct"; private String ip; private String port; // private ImageB Utton but7 = null; private EditText ServerIp = null; private EditText ServerPort = null; private Button btn_login = null; private CheckBox remember; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); super. setContentView (R. layout. login); // click this on the "login" page. serverIp = (Edi TText) super. findViewById (R. id. et_ip); this. serverPort = (EditText) super. findViewById (R. id. et_port); btn_login = (Button) this. findViewById (R. id. btn_login); remember = (CheckBox) this. findViewById (R. id. cb_remember); loadIpPort (); // load the IP address and port btn_login.setOnClickListener (new View. onClickListener () {// The Event @ Overridepublic void onClick (View arg0) after the "login" button {// TODO Auto-generated method stub // Fault Tolerance judge ip = ServerIp. getText (). toString (). trim (); port = ServerPort. getText (). toString (). trim (); ServerIp. requestFocus (); if (ip = null | ip. trim (). equals ("") ServerIp. setError ("Enter the IP address! "); If (port = null | port. trim (). equals (" ") ServerPort. setError (" enter the port number! "); Else {connect () ;}return ;}) ;}public void saveIpPort () // Save the IP address and port {SharedPreferences uiState = getSharedPreferences (" RS485 Controller ", MODE_PRIVATE); Editor et = uiState. edit (); et. putString ("ip", ServerIp. getText (). toString (); et. putString ("port", ServerPort. getText (). toString (); et. commit ();} public void loadIpPort () // load the IP address and port {SharedPreferences uiState = getSharedPreferences ("RS485 Controller ", MODE_PRIVATE); ServerIp. setText (uiState. getString ("ip", "192.168.1.180"); ServerPort. setText (uiState. getString ("port", "8899");} public void connect () {Toast. makeText (Login. this, "Connecting ...... ", Toast. LENGTH_SHORT ). show (); new Thread (new Runnable () {@ Overridepublic void run () {try {mSocket = new Socket (InetAddress. getByName (ip), Integer. parseInt (port); // mSocket = new Socket ("192.168.1.180", 8899); ops = mSocket. getOutputStream (); ips = mSocket. getInputStream ();} catch (Exception e) {e. printStackTrace ();} finally {} handler. sendMessage (handler. obtainMessage ());}}). start ();} // message processing queue private Han Dler handler = new Handler (new Handler. callback () {@ Override public boolean handleMessage (Message msg) {if (mSocket = null) {Toast. makeText (Login. this, "connection failed. Please log in again! ", Toast. LENGTH_SHORT). show ();} else {Toast. makeText (Login. this," connection successful! ", Toast. LENGTH_SHORT ). show (); if (remember. isChecked () {saveIpPort () ;}// Save the IP address and port Intent intent = new Intent (); intent. setClass (Login. this, Relay. class); startActivity (intent); // enter the Login page // finish ();} return false ;}});}




First:





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.