LED control using Arduino and Android ( part 2 : Android apk )
In this Part we going see step by step how to making android apk.
Android: New Project
When the build is finished, a “Hello world!” screen will be open , to create the layout of the apk, we need to add :
Text = The text to be displayed.
Id = the id of this widget.
Text = The text to be displayed.
Id = the id of this widget.
Now the main activity is finished, you can see that all widget used are shown on Components Tree.
Code source activity_device_list.xml on GITHUB
Android: Class Code Part 1.
On the left side there’s a folder called “app “, open it and you’ll see other folder called “java”.
To start an activity:
An Activity represents a single screen in an app. You can start a new instance of an Activity by passing an Intent to startActivity(). The Intent describes the activity to start and carries any necessary data.
A Service is a component that performs operations in the background without a user interface. You can start a service to perform a one-time operation (such as download a file) by passing an Intent to startService(). The Intent describes the service to start and carries any necessary data.
A broadcast is a message that any app can receive. The system delivers various broadcasts for system events, such as when the system boots up or the device starts charging. You can deliver a broadcast to other apps by passing an Intent to sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().
We need to create na new activity. If you’re following this tutorial
step-by-step, you’re seeing anerror at:
Intent i = new Intent(DeviceList.this,ledControl.class);
The error happens because there’s no ledControl classin the package.Let’s create a new activity called ledControl
Name it to ledControl and finish;
All over again, a “Hello world!” screen will be seen
This second layout will have three buttons,one TextView and a seekbar:
Android Manifest:
you can see the full project on github .
![]() |
| Ghassen Ben Taher .© |
Android: New Project
- Open Android Studio and create a new Project: File > New Project.
- A pop up Windows will appear. Change the Application Name and Company Name:
- Click next to choose the target of the application.
- Click next and choose a Blank Activity.
- Click next and rename the Activity Name to “DeviceList”.
- Now click “finish” and the Project will be create
When the build is finished, a “Hello world!” screen will be open , to create the layout of the apk, we need to add :
- TextView to display some hint to the user;
Text = The text to be displayed.
Id = the id of this widget.
- Button to show the paired devices.
Text = The text to be displayed.
Id = the id of this widget.
- ListView to show the paired devices;
Now the main activity is finished, you can see that all widget used are shown on Components Tree.
Code source activity_device_list.xml on GITHUB
Android: Class Code Part 1.
On the left side there’s a folder called “app “, open it and you’ll see other folder called “java”.
- Open DeviceList class;
- Import the followings packages:// DeviceList.java on Github
To start an activity:
An Activity represents a single screen in an app. You can start a new instance of an Activity by passing an Intent to startActivity(). The Intent describes the activity to start and carries any necessary data.
- To start a service:
A Service is a component that performs operations in the background without a user interface. You can start a service to perform a one-time operation (such as download a file) by passing an Intent to startService(). The Intent describes the service to start and carries any necessary data.
- To deliver a broadcast:
A broadcast is a message that any app can receive. The system delivers various broadcasts for system events, such as when the system boots up or the device starts charging. You can deliver a broadcast to other apps by passing an Intent to sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().
We need to create na new activity. If you’re following this tutorial
step-by-step, you’re seeing anerror at:
Intent i = new Intent(DeviceList.this,ledControl.class);
The error happens because there’s no ledControl classin the package.Let’s create a new activity called ledControl
Android: Layout Part 2
.
- Go to app > java > com.exemple.ghassenbentaher.androidbluetoothledcontrol
- Right click,NewActivity > Blank Activity
Name it to ledControl and finish;
All over again, a “Hello world!” screen will be seen
This second layout will have three buttons,one TextView and a seekbar:
- Turn On= Turns the LED On;
- Turn Off= Turns the LED Off;
- Disconnect= Closes Bluetooth Connection;
- Indicator;
- Brightness= control the brightness.
So Let’s add them:
Code source activity_led_control.xml on GITHUB
Android: Class Code Part 2
- Open ledControl class
- import the following packages: // LedControl.java GITHUB
Android Manifest:
Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory.
The manifest file presents essential information about your app to
the Android system,information the system must have before itcan run any
of the app’s code.
This apk uses Bluetooth Adapter and it is not available in
emulator, you must test it in a running device, but before you have to
add some users-permissions, otherwise the apk will crash.
In App folder, open manifests > AndroidManifest.xml
Add the following code to allow user-permision to use Bluetooth Device
- <uses-permission android:name= “android.permission.BLUETOOTH_ADMIN”/>
-
<uses-permission android:name= “android.permission.BLUETOOTH”/>
-
Rebuild the project at: Build Menu > Rebuild Project
you can see the full project on github .




Comments
Post a Comment