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

问题描述:

Android device name == "BlueZ"?在Android源代码中设置蓝牙设备名称?

我的问题是非常相似,这一次,我需要知道如何改变BlueZ显示实际的设备名称,即从build.prop阅读它,而不是显示“的BlueZ”

我发现main.confexternal/bluetooth/bluez/src/main.conf(可能略有偏离),它包含一行关于设备名称的变量,其变量设置为“BlueZ”。我试图将其更改为%d%h,两者均未作任何更改。我将尝试手动将其设置为设备名称,但我希望此修补程序可用于多个设备。

任何想法?

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

我试过代替上述两个变量,但都没有任何效果。

从外部应用程序怎么样? 您可以制作一个Android版本,并且在最后一个状态下运行一个应用程序来更改Android设备名称?

您可以使用IBluetooth.aidl - > setName更改蓝牙名称。

教程可以找到here,其进一步参考this

总之,在src中制作一个包android.bluetooth,在它里面复制粘贴IBluetooth.aidl和IBluetoothCallback.aidl(你可以在前面的链接中找到它们)。

在您的代码中,导入包: import android.bluetooth.IBluetooth;

然后实现这种方法来获得蓝牙对象:

@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; 
} 

然后例如该目的: IBluetooth IB = getIBluetooth();

并可能使用 ib.setName(“something”);