Set bluetooth name android

Set Bluetooth device name in Android Source Code?

Android device name == «BlueZ»? My question is very similar to this one, I need to know how to change BlueZ to display the actual device name, i.e. reading it from the build.prop, as opposed to displaying «BlueZ» I found the main.conf in external/bluetooth/bluez/src/main.conf (Might be slightly off) and it contains a line regarding the device name, with the variable set to «BlueZ». I tried changing it to both %d and %h , neither of which made any change. I’m going to try setting it to the device name manually, but I’d prefer that this fix be usable across several devices. Any ideas?

# Default adaper name # %h - substituted for hostname # %d - substituted for adapter id Name = "Bluez" 

1 Answer 1

What about from an outside app? You could just make an Android build and, at the last state, run an app to change the Android device name?

You can use IBluetooth.aidl -> setName to change the Bluetooth name.

Tutorials can be found here, which further references this.

In short, in src you make a package android.bluetooth, Inside it you copy paste IBluetooth.aidl and IBluetoothCallback.aidl (you can find them in the previous link).

In your code, import the package: import android.bluetooth.IBluetooth;

Then implement this method to get the Bluetooth object:

@SuppressWarnings("rawtypes") private IBluetooth getIBluetooth() < IBluetooth ibt = null; try < Class c2 = Class.forName("android.os.ServiceManager"); Method m2 = c2.getDeclaredMethod("getService", String.class); IBinder b = (IBinder) m2.invoke(null, "bluetooth"); Class c3 = Class.forName("android.bluetooth.IBluetooth"); Class[] s2 = c3.getDeclaredClasses(); Class c = s2[0]; Method m = c.getDeclaredMethod("asInterface", IBinder.class); m.setAccessible(true); ibt = (IBluetooth) m.invoke(null, b); >catch (Exception e) < Log.e("flowlab", "Erroraco. " + e.getMessage()); >return ibt; > 

Then instance this object: IBluetooth ib =getIBluetooth();

and probably use ib.setName(«something»);

Источник

Set Bluetooth device name in Android Source Code?

I’m going to try setting it to the device name manually, but I’d prefer that this fix be usable across several devices. My question is very similar to this one, I need to know how to change to display the actual device name, i.e. reading it from the build.prop, as opposed to displaying «BlueZ» I found the in (Might be slightly off) and it contains a line regarding the device name, with the variable set to «BlueZ».

Set Bluetooth device name in Android Source Code?

My question is very similar to this one, I need to know how to change BlueZ to display the actual device name, i.e. reading it from the build.prop, as opposed to displaying «BlueZ»

I found the main.conf in external/bluetooth/bluez/src/main.conf (Might be slightly off) and it contains a line regarding the device name, with the variable set to «BlueZ». I tried changing it to both %d and %h , neither of which made any change. I’m going to try setting it to the device name manually, but I’d prefer that this fix be usable across several devices.

# Default adaper name # %h - substituted for hostname # %d - substituted for adapter id Name = "Bluez" 

I’ve tried substituting the above two variables, but neither seem to have any effect.

Читайте также:  Блютуз гарнитура nokia bh 200

What about from an outside app? You could just make an Android build and, at the last state, run an app to change the Android device name?

You can use IBluetooth.aidl -> setName to change the Bluetooth name.

Tutorials can be found here, which further references this.

In short, in src you make a package android.bluetooth, Inside it you copy paste IBluetooth.aidl and IBluetoothCallback.aidl (you can find them in the previous link).

In your code , import the package: import android.bluetooth.IBluetooth;

Then implement this method to get the Bluetooth object:

@SuppressWarnings("rawtypes") private IBluetooth getIBluetooth() < IBluetooth ibt = null; try < Class c2 = Class.forName("android.os.ServiceManager"); Method m2 = c2.getDeclaredMethod("getService", String.class); IBinder b = (IBinder) m2.invoke(null, "bluetooth"); Class c3 = Class.forName("android.bluetooth.IBluetooth"); Class[] s2 = c3.getDeclaredClasses(); Class c = s2[0]; Method m = c.getDeclaredMethod("asInterface", IBinder.class); m.setAccessible(true); ibt = (IBluetooth) m.invoke(null, b); >catch (Exception e) < Log.e("flowlab", "Erroraco. " + e.getMessage()); >return ibt; > 

Then instance this object: IBluetooth ib =getIBluetooth();

and probably use ib.setName(«something»);

Android how to get the name of connected bluetooth, i want to know how to get the name of the connected bluetooth device in android here is the code NetworkInfo bluetooth = connectivityManager .getNetworkInfo(ConnectivityManager.TYPE_BLUETOOTH); if

How to get list of connected bluetooth devices on android

android get connected bluetooth devices

BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); List connected = manager.getConnectedDevices(GATT); Log.i("Connected Devices: ", connected.size()+"");

Java — Display Android Bluetooth Device Name, The below code will get u the bluetooth name, here mBluetoothAdapter is of type BluetoothAdapter. String android_id = … Code samplepublic String getLocalBluetoothName()String name = mBluetoothAdapter.getName();Feedback

Android Bluetooth List Paired Devices Example

The getBoundedDevices() method of BluetoothAdapter class provides a set containing list of all paired or bounded bluetooth devices.

In this example, we are checking if the bluetooth is turned off, if yes then turn it on and list all the paired devices.

activity_main.xml

Drag one textview from the pallete, now the activity_main.xml file will like this:

Provide Permission

You need to provide following permissions in AndroidManifest.xml file.

The full code of AndroidManifest.xml file is given below.

Activity class

Let’s write the code to provide the list of paired (bounded) bluetooth devices.

package com.example.bluetoothshowpaired; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import java.util.Set; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.Intent; import android.widget.TextView; public class MainActivity extends Activity < TextView textview1; private static final int REQUEST_ENABLE_BT = 1; BluetoothAdapter btAdapter; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) < super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textview1 = (TextView) findViewById(R.id.textView1); // Getting the Bluetooth adapter btAdapter = BluetoothAdapter.getDefaultAdapter(); textview1.append("\nAdapter: " + btAdapter); CheckBluetoothState(); >/* It is called when an activity completes.*/ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) < super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_ENABLE_BT) < CheckBluetoothState(); >> @Override protected void onDestroy() < super.onDestroy(); >private void CheckBluetoothState() < // Checks for the Bluetooth support and then makes sure it is turned on // If it isn't turned on, request to turn it on // List paired devices if(btAdapter==null) < textview1.append("\nBluetooth NOT supported. Aborting."); return; >else < if (btAdapter.isEnabled()) < textview1.append("\nBluetooth is enabled. "); // Listing paired devices textview1.append("\nPaired Devices are:"); Setdevices = btAdapter.getBondedDevices(); for (BluetoothDevice device : devices) < textview1.append("\n Device: " + device.getName() + ", " + device); >> else < //Prompt user to turn on Bluetooth Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); >> > @Override public boolean onCreateOptionsMenu(Menu menu) < // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; >>
You need to run it on the real device (e.g. mobile) to test the application.

How to get current Bluetooth name in android?, This example demonstrate about How to get current Bluetooth name in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill …

Читайте также:  Блютуз гарнитура чувствительность микрофона

Источник

How to Change the Bluetooth Name on Android

Tim Fisher has more than 30 years’ of professional technology experience. He’s been writing about tech for more than two decades and serves as the SVP and General Manager of Lifewire.

Ryan Perian is a certified IT specialist who holds numerous IT certifications and has 12+ years’ experience working in the IT industry support and management positions.

What to Know

  • Most Android phones: Settings >Connected Devices >Connection preferences >Bluetooth >Device name.
  • Change the Bluetooth name to make your device more recognizable.
  • The Bluetooth name can usually be different from the overall device name.

This article explains how to change the Bluetooth name on Android to adjust how other devices identify your phone. These directions should work on modern Android versions from most phone manufacturers.

How Do I Change My Bluetooth Name?

Editing the Bluetooth name solves the problem of now knowing which device you’re connecting to over Bluetooth. If you have multiple phones or tablets with the same name, or you’re never sure if you’re selecting the correct device, renaming the Bluetooth connection can help.

Using a Samsung Galaxy device? These phones don’t have a Bluetooth-specific name option but instead, rely on the device name. See the bottom of this page to learn how to change that name.

  1. Open the Settings app, or swipe down from the top of the screen twice to find the settings/gear icon.

Settings, connected devices, connection preferences, and Bluetooth highlighted on Android

Go to Connected Devices >Connection preferences >Bluetooth.

On some devices, go instead to Connected Devices > Bluetooth. Other devices list Bluetooth right away without being nested in another folder.

Bluetooth device name settings on Android

Change the Bluetooth name and then tap Rename, the checkmark, OK, or whatever «save» button your device uses.

Change Bluetooth Name on Samsung Galaxy

Most phones let you use one name for Bluetooth and another for the device itself. When you plug your phone into a computer, for example, it’s the device name that’s visible. But using Bluetooth to pair your Android and computer (or car, etc.) will display your phone’s Bluetooth name.

Some devices, like Samsung Galaxy phones, don’t include the option to change the Bluetooth name. Since they use the Bluetooth device name, you can change that name to rename the Bluetooth connection.

Changing the device name doesn’t require as many steps, but it does differ between devices. Whether you have a Samsung Galaxy phone or one from another manufacturer, these are the various menu buttons that lead to the device name settings: Settings > About phone (or About Tablet or About Device) > Device name (or Edit).

Источник

Change the Android bluetooth device name

I know it’s possible to get the local device name as described in the solution to this question Display Android Bluetooth Device Name What I’m interested in knowing is, can I change the local buetooth name (the one other devices see when I’m in discovery mode) programaticlly. I know you can change it by hand, but I’m writing and app and I want to be able to change the name (add a simple flag) so other devices with the same application can scan and instantly know if the phone is also running the app. tl;dr: How can I change the bluetooth device name on android?

3 Answers 3

Yes you can change your device name using setName(String name) of BluetoothAdapter type.Following is the sample code:

 private BluetoothAdapter bluetoothAdapter = null; bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); void ChangeDeviceName()

This does seem to work, but there does also appear to be some caching issues (ie. connected devices always had old name). If anyone comes across this issue go into the phones bluetooth settings and view the devices, this seemed to clear the cache for me

Thanks for the original answer, here are a few things I found when implementing that might help someone else out.

1) BT has to be enabled for setName() to work.

2) It takes time for BT to Enable. ie. you Can’t just call enable() then setName()

3) It takes time for the name to «sink in». ie. you can’t call getName() right after setName() and expect the new name.

So, here is a snippet of code I came up with to use a runnable to get the job done in the background. It is also time bound to 10seconds, so it won’t run forever if there is a problem.

Finally, this is part of our power on check, and we normally leave BT disabled (due to battery). So, I turn BT back off after, you may not want to do that.

// BT Rename // final String sNewName = "Syntactics"; final BluetoothAdapter myBTAdapter = BluetoothAdapter.getDefaultAdapter(); final long lTimeToGiveUp_ms = System.currentTimeMillis() + 10000; if (myBTAdapter != null) < String sOldName = myBTAdapter.getName(); if (sOldName.equalsIgnoreCase(sNewName) == false) < final Handler myTimerHandler = new Handler(); myBTAdapter.enable(); myTimerHandler.postDelayed( new Runnable() < @Override public void run() < if (myBTAdapter.isEnabled()) < myBTAdapter.setName(sNewName); if (sNewName.equalsIgnoreCase(myBTAdapter.getName())) < Log.i(TAG_MODULE, "Updated BT Name to " + myBTAdapter.getName()); myBTAdapter.disable(); >> if ((sNewName.equalsIgnoreCase(myBTAdapter.getName()) == false) && (System.currentTimeMillis() < lTimeToGiveUp_ms)) < myTimerHandler.postDelayed(this, 500); if (myBTAdapter.isEnabled()) Log.i(TAG_MODULE, "Update BT Name: waiting on BT Enable"); else Log.i(TAG_MODULE, "Update BT Name: waiting for Name (" + sNewName + ") to set in"); >> > , 500); > > 

Источник

Оцените статью
Adblock
detector