Smart Car Seven "PC Android"

Source: Internet
Author: User
Tags connect socket

Then the above serial port protocol, this article again describes how to implement the Android side. Now the programmer division is very clear, many will C not Java, Java will not necessarily develop Android. And my job is to develop Java background, Android development can only be an amateur player, but the development of a small car control program is still possible.
Let's start with the Android development environment, Android Studio. Such as:



After we create a new project, the main files to be changed are in this main folder. The Java folder is a. java file that puts the program logic. The res file is placed in the configuration file for the interface presentation, Androidmanifest.xml is the ability to configure the entire project, entry code, and so on.
My design is this, in the first interface to show the Bluetooth list and control buttons. After selecting the Bluetooth connection, hide the Bluetooth list, the interface is only the control button. The following progress bar-like control is used to set the speed using the Android PWM feature.



After connecting the Bluetooth:



This set up a lot of small technical points, such as setting a horizontal screen, how to hide the control, how the control adapts to the screen size. These in the professional Android programmer eye may not be a thing, but I still spend a lot of time to check when I do. For example, how to automatically adapt to the screen after hiding, I use a relative layout. This can be seen in the Dark Horse Programmer's Android video course.

Here's a simple and important technical point, how does Bluetooth stay connected? During the actual operation, the user may find that Bluetooth is disconnected for no apparent reason. At first I had to restart the app to connect, really to change the following lines of code:
try {
Os.write (Msg.getbytes ());
} catch (IOException e) {
E.printstacktrace ();
Send exception, re-connect socket
SYSTEM.OUT.PRINTLN ("Send exception, re-connect socket");
Connectsocket (lvdevices);
}
Explain the OS is the OutputStream, Bluetooth output stream. MSG is the message content to be sent. If an exception occurs, then connect to Bluetooth. In fact, the best thing is to send the content again after the connection.
Well, a simple control program is finished.

Smart Car Seven "PC Android"

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.