Pages

Subscribe:

Thursday, February 17, 2011

Android - How to find Bluetooth Status

Below is a  sample code to check the bluetooth status in Android


package com.blue;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.os.Bundle;
import android.widget.Toast;

public class BluetoothStatus extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();

String toastText;
if (bluetooth.isEnabled()) {
String address = bluetooth.getAddress();
String name = bluetooth.getName();
toastText = name + " : " + address;
} else
toastText = "Bluetooth is not enabled";

Toast.makeText(this, toastText, Toast.LENGTH_LONG).show();

bluetooth.setName("Enrichware");

}
}

2 comments:

Vishal (SSVARLIFE) said...

Can you give a sample code to connect another bluetooth device????

Appzuniverse said...

Really good code, am tested this code, this code having no bugs ..Thanks
Android apps development company India

Post a Comment