android 6.0没有返回确切的蓝牙mac地址

时间:2015-10-15 09:18:14

标签: android bluetooth

db.coll.aggregate([
    {
        $group: {
            "_id": "$fieldID",
            "maxThing": { 
                "$max": { 
                    "$divide": [ 
                        { "$ifNull": [ "$fieldA", "$fieldC" ] } ,
                        { "$ifNull": [ "$fieldB", "$fieldD" ] }
                    ] 
                } 
            }       
        }
    }
])

请告诉我在蓝牙中获取当前mac地址所需的问题或设置

我已经尝试了以下代码,它返回空

 BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

mBluetoothAdapter.getAddress(); returning the 02:00:00:00:00:00.

3 个答案:

答案 0 :(得分:2)

以下方法将在Android 6.0中提供蓝牙macAddress

public static final String SECURE_SETTINGS_BLUETOOTH_ADDRESS = "bluetooth_address";


public static String getBluetoothMacAddress(Context mContext) {


        BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();


        // BluetoothAdapter.getDefaultAdapter().DEFAULT_MAC_ADDRESS;
        // if device does not support Bluetooth
        if (mBluetoothAdapter == null) {
            Log.d(TAG, "device does not support bluetooth");
            return null;
        }

        String address = mBluetoothAdapter.getAddress();
        if (address.equals("02:00:00:00:00:00")) {

            //  System.out.println(">>>>>G fail to get mac address " + address);

            try {


                ContentResolver mContentResolver = mContext.getContentResolver();

                address = Settings.Secure.getString(mContentResolver, SECURE_SETTINGS_BLUETOOTH_ADDRESS);
                DebugReportOnLocat.ln(">>>>G >>>> mac " + address);

            } catch (Exception e) {


            }


        } else {

            // System.out.println(">>>>>G sucess to get mac address " + address);
        }
        return address;
    }

答案 1 :(得分:1)

此功能在Android 6中已停用。

  

为了向用户提供更好的数据保护,从此版本开始,Android会删除使用Wi-Fi和蓝牙API的应用程序对设备的本地硬件标识符的编程访问。 WifiInfo.getMacAddress()和BluetoothAdapter.getAddress()方法现在返回一个常量值02:00:00:00:00:00。

{{3}}

如果有人找到解决方法,请告诉我。

答案 2 :(得分:0)

使用此方法获取MAC地址:

/**
 * get bluetooth adapter MAC address
 * @return MAC address String
 */
public static String getBluetoothMacAddress() {

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

// if device does not support Bluetooth
if(mBluetoothAdapter==null){
    Log.d(TAG,"device does not support bluetooth");
    return null;
}

return mBluetoothAdapter.getAddress();

}