Teach you how to do Bluetooth chat application (i)-Design plan

Source: Internet
Author: User

Objective

With " calculators " and " video players " We've been able to start developing some more decent apps.

Today, we're going to start making a " Bluetooth chat " app. This application is actually very simple, there is no cool interface, is one-on-one, through Bluetooth connection two devices, let two people send each other information.

Do not think it is too boring, no practical, in fact, we just want to let you start to contact the network programming (Bluetooth and WiFi are wireless connection technology, their program design methods and ideas are very similar).

In addition, learned to use Bluetooth, for everyone opened the technology development of another door-the internet of things, now many IoT hardware needs to use Bluetooth technology to connect, really with stone. This technology will be mastered later, you can combine our other introduction of Bluetooth car documentation, the development of Bluetooth car remote control.

This app is based on apps that Google offers in the Android SDK Bluetooth Chat . Google's example only code, no explanation, so for many beginners will have a lot of questions. Here, Google's sample program has been greatly modified, and beautify the interface, so that it is easy for beginners to learn, from the principle of knowledge to design solutions will be discussed in detail. We hope that through this section of the study, the communication between the different equipment development has a holistic understanding, and the use of this technology, as our next step to develop the stepping stone.

The reader for this article is:

    1. A preliminary understanding of the development of Android students;
    2. Ready to do IoT development, but little white for Android (control side) development feeling confused;

Before you start, let's say you're ready to do the following:

    • A development with a notebook computer, and set up a good development environment;
    • Two Android devices (mobile phones or tablets);
    • A data cable (usually a micro USB cable) connecting the computer and the Android device;
    • one or both days;
    • Patience and curiosity;

The code for this article can be downloaded from the example code of the Bean network.

/*******************************************************************/
* Copyright Notice
* This tutorial is only published in CSDN and the green Bean Network, other websites appear this tutorial is infringing.
/*******************************************************************/

1th Section Design plan

When planning the product, we must first do the addition, as far as possible it can have the function of digging out, and then do subtraction, not practical, or input cost-effective function put a put, make the first version of the product; Finally, according to the user feedback, coupled with the regret of the previous version of the product to upgrade the product.

This is a cycle of development, spiral rise of the process. This can put the limited development resources to the most important place, get the user's feedback, as far as possible to design the user really need the product.

1.1 Possible function points

As a small application of instant messaging, we can completely design it as "" or "QQ", the only difference being that this chat app is data transfer via Bluetooth instead of WiFi. Therefore, we can temporarily list the features it might have:

    1. Two devices can be connected to each other;
    2. Connected devices can transmit data, such as text, pictures, voice, music, and even real-time video;
    3. The content sent by both parties can be displayed;
    4. Can edit the personal information of either party, such as Avatar, nickname, personality description and so on, the establishment of communications and other parties can view mutual information;
    5. Can view the history of both chats;
    6. Can search the history of chat;
    7. You can save the image, voice, or video sent by the other person individually.
      ......

There are too many features that can be added.

1.2 Filtering of functions

As you can see from the details listed above, there are so many features that can be given to this chat app, so we have to sift through our abilities and energies to do the subtraction of functions.

    1. The interconnection of the devices is necessary, and the basis of the realization of the chat is based on this.
    2. The transmission of data between devices is carried out in binary form, which can transmit text, pictures, voice, music, video and other information.
    3. Need to show the content of the chat between the two sides, so that users can judge the context.

The above 3 is the core function of Bluetooth chat application, other functions are the expansion of these 2 basic functions,

    1. Personal data, some words of course is very good, but does not affect the use of communication functions of two people;
    2. View the history chat record, view the last time the connection was established chat record of course there is a necessary function, but in order to simplify the problem, we still temporarily put this function, save to the next version to join it;

As for the other functions, it's farther away. We are not going to do it for the time being.

1.3 Performance considerations for Bluetooth technology

Transmitting data using Bluetooth (or WiFi) is a binary data transfer. Text, pictures, voice, music, real-time video, and so on are essentially binary data, but their format is not the same. So in theory, the transmission of these kinds of information is possible.

However, any wireless transmission technology, the amount of data transmitted within a unit of time and the distance between the transmission is limited. High transmission requirements should be counted real-time video content, every second to reach 24 frames, so the requirements of transmission speed is conceivable. So the transmission speed of Bluetooth can be achieved?

Different data types, the requirements for transmission is different, the transmission of what kind of data is more appropriate? At this stage, let's simplify the problem and let it send a simple string.

As the carrier of any data, binary data stream is the most basic, and the string can be regarded as a kind of binary data with special structure. So, for the sake of simplicity, the first step is to assume that only the text content is transferred.

So far, there is no technical barrier to achieving the full functionality.

1.4 Functions of the present stage

Based on the above discussion, we determine the specific features of the Bluetooth chat app:

    1. Can be searched around the Bluetooth enabled devices, the results of the search display;
    2. Discover can connect the device, click the result of a search, can actively connect the other side;
    3. Can be searched by other Bluetooth devices around;
    4. After receiving the connection request from other devices, can accept the request of the other, establish a connection;
    5. Connection process, you can cancel the connection, the connection is successful, can be disconnected;
    6. When two devices are connected, the data can be transmitted in the form of binary data, and the content of the data is simple text;
    7. The content sent by both parties can be displayed separately, but does not save the previous chat record;
    8. You cannot delete the displayed information in the list of recorded chats;
    9. When the device is connected, it can not be connected with other devices, between each other, can only connect one device at a time;
1.5 Assumptions of functional conditions

We have identified the functions of the Bluetooth chat application, and we need to give some basic assumptions about functional design.

    1. When the two Bluetooth devices are connected, if the Bluetooth function of one of the devices is manually closed by the user, how do we need to handle the application? For this, in order to simplify the development of the first version of the application, it is simple to assume that once the Bluetooth function is turned on, the application is running, the Bluetooth function will not be closed.

    2. After the main interface of the program exits, can you continue to receive data sent from the other side in the background? Like that, as long as the app does not quit and has a network, it can always receive messages from friends? From the point of view of simplifying the problem, we assume that once the main interface of the program exits, there is no need to continue to receive data in the background.

1.6 About regrets

For those features that are not added at this stage, look forward to joining later.

For simple designs that simplify development and reduce development time, expect to optimize and refine in the next version of the program.

Teach you how to do Bluetooth chat application (i)-Design plan

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.