Developing Bluetooth Application
In this video we are going to develop a Bluetooth application.
First of all we will design the Layout of our application, so for that we will go to main.xml file. We have taken one linear layout and a textview.
We need to work with Bluetooth so we have to specify some certain conditions. So for that we will go to our androidmanifest.xml file and give the following permissions,
Now we will design a MainActivity and also a class named as 'Connections'. Inside that we will first declare a variable 'state' and assign it's value as false.
private static boolean state=false;
Now we will design a bluetooth method and then write the code for it in Connections.java ,
public static boolean blueTooth()
System.out.println("Bluetooth is Disable...");
else if (bluetooth.isEnabled())
System.out.println(name + " : " + address);
Now we will design in our MainActivity.java file,
public void onCreate(Bundle savedInstanceState)
private void setBluetoothData()
out.append("\nAdapter: " + adapter.toString() + "\n\nName: " + adapter.getName() + "\nAddress: " + adapter.getAddress());
Toast.makeText(this,"Bluetooth NOT supported.Aborting.",
out.append("\nDone with discovery...\n");
Now we will call the method for checking that is our Bluetooth enable or disable in MainActivity.java,
Intent enableBtIntent=new Intent(
Now we will run our code and execute on a real device. Our code is running successfully and all the information regarding devices bluetooth appears in front of our screen.
Have a friend to whom you would want to share this course?