简体   繁体   English

在Android源代码中设置蓝牙设备名称?

[英]Set Bluetooth device name in Android Source Code?

Android device name == "BlueZ"? Android设备名称==“ 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" 我的问题与这一问题非常相似,我需要知道如何更改BlueZ以显示实际的设备名称,即从build.prop中读取它,而不是显示“ 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". 我在external/bluetooth/bluez/src/main.conf找到了main.conf (可能略有关闭),其中包含有关设备名称的一行,变量设置为“ BlueZ”。 I tried changing it to both %d and %h , neither of which made any change. 我尝试将其更改为%d%h ,但都没有进行任何更改。 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? 您可以制作一个Android版本,然后在最后一个状态下运行一个应用程序来更改Android设备名称?

You can use IBluetooth.aidl -> setName to change the Bluetooth name. 您可以使用IBluetooth.aidl-> setName更改蓝牙名称。

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). 简而言之,在src中创建一个包android.bluetooth,在其中复制粘贴IBluetooth.aidl和IBluetoothCallback.aidl(您可以在上一个链接中找到它们)。

In your code , import the package: import android.bluetooth.IBluetooth; 在您的代码中 ,导入包:import android.bluetooth.IBluetooth;

Then implement this method to get the Bluetooth object: 然后实现此方法以获取Bluetooth对象:

@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(); 然后实例化该对象:IBluetooth ib = getIBluetooth();

and probably use ib.setName("something"); 并可能使用ib.setName(“ something”);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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