简体   繁体   中英

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, ie 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"

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

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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM