Android Bluetooth UUID Sample
Android Bluetooth UUID Sample
JAVA PROGRAM
package com.example.bluetoothlist;
import java.util.Set;
import
import
import
import
import
import
import
android.os.Bundle;
android.app.Activity;
android.bluetooth.BluetoothAdapter;
android.bluetooth.BluetoothDevice;
android.content.DialogInterface;
android.content.DialogInterface.OnClickListener;
android.content.Intent;
import
import
import
import
import
import
android.view.Menu;
android.view.View;
android.widget.Button;
android.widget.ListView;
android.widget.TextView;
android.widget.Toast;
turnon.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent,
REQUEST_ENABLE_BT);
Set<BluetoothDevice> devices =
mBluetoothAdapter.getBondedDevices();
for (BluetoothDevice device : devices) {
out.append("\nFound device: " + device);
}
}
}
});
list.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Set<BluetoothDevice> devices =
mBluetoothAdapter.getBondedDevices();
for (BluetoothDevice device : devices) {
//Menu mArrayAdapter = null;
out.append("\nFound device: " +
device.getName()+ "\n" +"\nDevice name"+ device.getAddress());
});
turnoff.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mBluetoothAdapter.disable();
}
});}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
}}
XML CODE
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Bluetoothlist" >
<Button
android:id="@+id/list"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignLeft="@+id/button1"
android:layout_alignParentTop="true"
android:text="List" />
<TextView
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_marginTop="52dp"
android:text="List of devices" />
<Button
android:id="@+id/button1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="@+id/list"
android:layout_centerHorizontal="true"
android:onClick="showMessage"
android:text="TURN ON BT" />
<Button
android:id="@+id/turnoff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:layout_below="@+id/list"
android:layout_toRightOf="@+id/list"
android:text="TURN OFF" />
</RelativeLayout>
Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bluetoothlist"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.bluetoothlist.Bluetoothlist"
android:label="@string/app_name" >
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>