的默認(rèn)藍(lán)牙名稱為 Android Bluedroid
通過搜索你會找到如下文件 device/generic/common/bluetooth/bdroid_buildcfg.h
#ifndef _BDROID_BUILDCFG_H
#define _BDROID_BUILDCFG_H
#define BTM_DEF_LOCAL_NAME "Android Bluedroid"
#endif
如果單一情況你修改此處即可,但如果多臺燒錄此 room 的設(shè)備同時打開藍(lán)牙,你搜索到的藍(lán)牙名稱都為 BTM_DEF_LOCAL_NAME 對應(yīng)的值
為了避免此種情況,我們采用另一種修改方式
將藍(lán)牙名稱修改為 你當(dāng)前設(shè)備的 displayID,如果包含 _ ,則取 _ 之前的名稱再加上 mac 地址的后六位
舉個栗子, 設(shè)備 displayID 為 MTK6737-VT_V1.02 藍(lán)牙m(xù)ac地址為 EF:6D:3C:22:25:56, 則最終的藍(lán)牙名稱為 MTK6737-VT_222556文章來源:http://www.zghlxwxcb.cn/news/detail-850101.html
frameworks\base\core\java\android\bluetooth\BluetoothAdapter.java文章來源地址http://www.zghlxwxcb.cn/news/detail-850101.html
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
public boolean enable() {
if (isEnabled()) {
if (DBG) Log.d(TAG, "enable(): BT already enabled!");
updateBleName();//cczheng add
return true;
}
try {
boolean enableResult = mManagerService.enable(ActivityThread.currentPackageName());
if (enableResult) {
updateBleName();//cczheng add
}
return enableResult /*mManagerService.enable(ActivityThread.currentPackageName())*/;
} catch (RemoteException e) {Log.e(TAG, "", e);}
return false;
}
/**
* cczheng add updateBleName whenBluetooth enable
*/
private void updateBleName(){
final String ctag = "ccz";
final String bleName=getName();
Log.e(ctag,".bleName:"+bleName);
new Thread(){
@Override
public void run() {
super.run();
int timeCounter=0;
String macStr=null;
while(timeCounter<20){//500 *20 =10,000 ms
macStr=getAddress();
if(TextUtils.isEmpty(macStr) || macStr.contains("00:00:00")){
try { sleep(500); } catch (InterruptedException e) {}
}else{
break;
}
timeCounter++;
}
Log.e(ctag,".mac:"+macStr);
if(!TextUtils.isEmpty(macStr) && !macStr.contains("00:00:00")){
timeCounter=0;
macStr = macStr.substring(macStr.length() - 8, macStr.length());
macStr = macStr.replaceAll(":", "");
String display = android.os.Build.DISPLAY;
if (display.contains("_")){
display = display.split("_")[0];
}else{
display = "BT";
}
String newBleName = display + "_" + macStr;
Log.e(ctag,".newBleName:"+newBleName);
if(!newBleName.equals(bleName)){
if(bleName.equals("ANDROID BT")
|| bleName.contains("Android Bluedroid")
|| bleName.contains("BT")
|| bleName.contains(display + "_")){
try{
while (mService == null || mService.getState() != STATE_ON) {
try{ sleep(200); } catch (InterruptedException e){}
timeCounter++;
if (timeCounter > 20) {
break;
}
}
Log.e(ctag,".setbleName:"+newBleName);
mService.setName(newBleName);
}catch (RemoteException e){
e.printStackTrace();
}
Log.e(ctag,".setbleNameFinished:"+newBleName);
}
}
}
}
}.start();
}
到了這里,關(guān)于Android8.1 MTK平臺 修改藍(lán)牙默認(rèn)名稱的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!