7

How to display a bluetooth device name in android which uses Java? Any codes for me to refer to?

TunA
  • 91
  • 2
  • 2
  • 5

1 Answers1

21

The below code will get u the bluetooth name, here mBluetoothAdapter is of type BluetoothAdapter.

  public String getLocalBluetoothName(){
    if(mBluetoothAdapter == null){
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    }
    String name = mBluetoothAdapter.getName();
    if(name == null){
        System.out.println("Name is null!");
        name = mBluetoothAdapter.getAddress();
    }
    return name;
}
Hussain
  • 5,552
  • 4
  • 40
  • 50
  • Thank you Hussain! It works well with my code. But if I were to retrieve the handset address also works the same way? – TunA Jul 13 '11 at 06:53
  • `import android.provider.Settings.Secure; private String android_id = Secure.getString(getContext().getContentResolver(),secure.ANDROID_ID);` this will be useful to get the unique id for the android device – Hussain Jul 13 '11 at 06:57
  • @TunA:`TelephonyManager tManager = (TelephonyManager)myActivity.getSystemService(Context.TELEPHONY_SERVICE); String uid = tManager.getDeviceId();` Activity class. getDeviceID() will return the MDN or MEID of the device depending on which radio the phone uses (GSM or CDMA). – Hussain Jul 13 '11 at 07:00
  • but then it will be the serial number of the android device that I'm retrieving not the handset address of the bluetooth device that I had connected it to the PC.. Is there any way that you can explain to me clearly? – TunA Jul 13 '11 at 09:20
  • U need the address if the Bluetooth device? – Hussain Jul 13 '11 at 09:22
  • I need the address of the handset device by using bluetooth that is being plugged into my PC.. Can I ask what other information can I show using Bluetooth? – TunA Jul 13 '11 at 09:25
  • I think the `mAdapter.getAddress()` will do for u. U better go thro this link http://developer.android.com/reference/android/bluetooth/package-summary.html – Hussain Jul 13 '11 at 09:28
  • It works fine! Thank you Hussain! Does it works the same way if I want to retrieve the Bluetooth version? – TunA Jul 14 '11 at 03:12
  • Ya u can also take the bluetooth version from that itself. – Hussain Jul 14 '11 at 04:30