1. Introduction:
Bluetooth established a very low power, short range communication link between two devices.
Go to the link ai2.appinventor.mit.edu. Sign In with your gmail account. To start making your application, click on the Projects menu on the top left of the screen and select the “Start new project” and then give the name of your project.
Now, you are in the designer panel of your project, where you can layout the “user interfaces” of your app. You choose things for the user interface things like Buttons,Images, Text boxes to the palette.
2. Designer Panel:
Select the ListPicker component from user interface. ListPicker is the button, which displays the list of available bluetooth devices and handle the selection. You can change the text display on the listpicker to properties panel. You can also change the height, width, color using the same panel.
Click on the Layout from palette and select Horizontal arrangement. Horizontal arrangement component is to display a group of components laid out from left to right. We are using this component to display two buttons horizontally which is “Connect” and “Disconnect”.
After this, click and hold on the word “Button” in the palette, drag your mouse over to the Viewer and drop the button over the horizontal view and do same by dragging another button. These two buttons will look left to right. Rename the buttons from “Button1 to Connect” and “Button2 to Disconnect”, so that it will be easy to get them on block panel. Also change the text of buttons from properties, which will display on users screen.
Add a label text (optional), as a status about bluetooth connection.
At last, connectivity from palette select Bluetooth Client and drag and drop to the viewer panel. Note that, this is the hidden component. The only difference between bluetooth client and bluetooth server is that, there is a connect to device (ListPicker) button.
3. Block Editor:
The Blocks Editor is where you program the behavior of your app. There are Built-in blocks that handle things like math, logic, and text with each components you have added.
Click on the list picker and select ListPicker Before Picking and set the elements of list as available bluetooth devices.
Again click on list picker and select ListPicker After Picking and set the status label to Connect your Device. Now user need to connect selected device to bluetooth App.
By clicking on the connect button, connection will be established between selected device and application.
And by clicking on the disconnect button, bluetooth disconnects the connected device.
You can minimized the above code, by using listpicker as connect button also. After picking the device, the connect method will established the connection.
Final app will look like the above image in your phone. You can change color, text, width, height , background of the components.
You may download the source code of this App from here.
If you have any query please write us at support@roboindia.com
Thanks and Regards
Content Development Team
Robo India
https://roboindia.com