2011-07-12 60 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