2011-07-12 94 views

回答

15

下面的代碼將得到您的藍牙名稱,這裏mBluetoothAdapterBluetoothAdapter類型。

public String getLocalBluetoothName(){ 
    if(mBluetoothAdapter == null){ 
     mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
    } 
    String name = mBluetoothAdapter.getName(); 
    if(name == null){ 
     System.out.println("Name is null!"); 
     name = mBluetoothAdapter.getAddress(); 
    } 
    return name; 
} 
+0

謝謝Hussain!它適用於我的代碼。但是,如果我要檢索手機地址,其工作原理也是一樣的嗎? – TunA

+0

'import android.provider.Settings.Secure; private String android_id = Secure.getString(getContext()。getContentResolver(),secure.ANDROID_ID);'這將有助於獲取Android設備的唯一ID – Hussain

+0

@TunA:'TelephonyManager tManager =(TelephonyManager)myActivity.getSystemService (Context.TELEPHONY_SERVICE); String uid = tManager.getDeviceId();'活動類。 getDeviceID()將根據手機使用的無線電(GSM或CDMA)返回設備的MDN或MEID。 – Hussain