当前位置: 首页>>代码示例>>Java>>正文


Java BluetoothAdapter.getAddress方法代码示例

本文整理汇总了Java中android.bluetooth.BluetoothAdapter.getAddress方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothAdapter.getAddress方法的具体用法?Java BluetoothAdapter.getAddress怎么用?Java BluetoothAdapter.getAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.bluetooth.BluetoothAdapter的用法示例。


在下文中一共展示了BluetoothAdapter.getAddress方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAddress

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public static @Nullable String getAddress(final BluetoothAdapter adapter) {
    if (adapter == null)
        return null;

    final String address = adapter.getAddress();
    if (!MARSHMELLOW_FAKE_MAC.equals(address))
        return address;

    // Horrible reflection hack needed to get the Bluetooth MAC for Marshmellow and above.
    try {
        final Field mServiceField = BluetoothAdapter.class.getDeclaredField("mService");
        mServiceField.setAccessible(true);
        final Object mService = mServiceField.get(adapter);
        if (mService == null)
            return null;
        return (String) mService.getClass().getMethod("getAddress").invoke(mService);
    } catch (final Exception x) {
        throw new RuntimeException(x);
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:21,代码来源:Bluetooth.java

示例2: getBluetoothAddress

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public static String getBluetoothAddress(Context ctx,
		BluetoothAdapter adapter) {
	// Return the adapter's address if it's valid and not fake
	String address = adapter.getAddress();
	if (isValidBluetoothAddress(address)) return address;
	// Return the address from settings if it's valid and not fake
	address = Settings.Secure.getString(ctx.getContentResolver(),
			"bluetooth_address");
	if (isValidBluetoothAddress(address)) return address;
	// Let the caller know we can't find the address
	return "";
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:13,代码来源:AndroidUtils.java

示例3: getBluetoothMAC

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@SuppressWarnings("MissingPermission")
public static String getBluetoothMAC(Context context) {
    String result = null;
    try {
        if (context.checkCallingOrSelfPermission(Manifest.permission.BLUETOOTH)
                == PackageManager.PERMISSION_GRANTED) {
            BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter();
            result = bta.getAddress();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:15,代码来源:DeviceUtils.java

示例4: getBluMac

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public String getBluMac() {
    try {
        BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
        return (defaultAdapter == null || defaultAdapter.isEnabled()) ? defaultAdapter.getAddress() : "";
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:9,代码来源:DeviceInfo.java

示例5: getBluetoothAdapterAddress

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
private static String getBluetoothAdapterAddress(BluetoothAdapter bluetoothAdapter) {
    @SuppressLint("HardwareIds") // Pair-free peer-to-peer communication should qualify as an "advanced telephony use case".
    String address = bluetoothAdapter.getAddress();
    if (address.equals(FAKE_MAC_ADDRESS)) {
        Log.w(TAG, "bluetoothAdapter.getAddress() did not return the physical address");

        // HACK HACK HACK: getAddress is intentionally broken (but not deprecated?!) on Marshmallow and up:
        //   * https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-notifications
        //   * https://code.google.com/p/android/issues/detail?id=197718
        // However, we need it to establish pair-free Bluetooth Classic connections:
        //   * All BLE advertisements include a MAC address, but Android broadcasts a temporary, randomly-generated address.
        //   * Currently, it is only possible to listen for connections using the device's physical address.
        // So we use reflection to get it anyway: http://stackoverflow.com/a/35984808
        // This hack won't be necessary if getAddress is ever fixed (unlikely) or (preferably) we can listen using an arbitrary address.

        Object bluetoothManagerService = new Mirror().on(bluetoothAdapter).get().field("mService");
        if (bluetoothManagerService == null) {
            Log.w(TAG, "Couldn't retrieve bluetoothAdapter.mService using reflection");
            return null;
        }

        Object internalAddress = new Mirror().on(bluetoothManagerService).invoke().method("getAddress").withoutArgs();
        if (internalAddress == null || !(internalAddress instanceof String)) {
            Log.w(TAG, "Couldn't call bluetoothAdapter.mService.getAddress() using reflection");
            return null;
        }

        address = (String) internalAddress;
    }

    return address;
}
 
开发者ID:aarmea,项目名称:noise,代码行数:33,代码来源:BluetoothSyncService.java

示例6: getBluetoothMAC

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public static String getBluetoothMAC() {
    BluetoothAdapter mBlueth = BluetoothAdapter.getDefaultAdapter();
    return mBlueth.getAddress();
}
 
开发者ID:Datatellit,项目名称:xlight_android_native,代码行数:5,代码来源:DeviceInfo.java

示例7: getDiviceId

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public static String getDiviceId() {
    TelephonyManager TelephonyMgr = (TelephonyManager) Utils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
    String szImei = TelephonyMgr.getDeviceId();

    String m_szDevIDShort = "35" + //we make this look like a valid IMEI

            Build.BOARD.length() % 10 +
            Build.BRAND.length() % 10 +
            Build.CPU_ABI.length() % 10 +
            Build.DEVICE.length() % 10 +
            Build.DISPLAY.length() % 10 +
            Build.HOST.length() % 10 +
            Build.ID.length() % 10 +
            Build.MANUFACTURER.length() % 10 +
            Build.MODEL.length() % 10 +
            Build.PRODUCT.length() % 10 +
            Build.TAGS.length() % 10 +
            Build.TYPE.length() % 10 +
            Build.USER.length() % 10; //13 digits

    String m_szAndroidID = Settings.Secure.getString(Utils.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);

    WifiManager wm = (WifiManager) Utils.getContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    String m_szWLANMAC = wm.getConnectionInfo().getMacAddress();

    BluetoothAdapter m_BluetoothAdapter = null; // Local Bluetooth adapter
    m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    String m_szBTMAC = m_BluetoothAdapter.getAddress();

    StringBuilder stringBuilder = new StringBuilder();

    if (!TextUtils.isEmpty(szImei)) {
        stringBuilder.append(szImei);
    }

    if (!TextUtils.isEmpty(m_szDevIDShort)) {
        stringBuilder.append(m_szDevIDShort);
    }

    if (!TextUtils.isEmpty(m_szAndroidID)) {
        stringBuilder.append(m_szAndroidID);
    }

    if (!TextUtils.isEmpty(m_szWLANMAC)) {
        stringBuilder.append(m_szWLANMAC);
    }

    if (!TextUtils.isEmpty(m_szBTMAC)) {
        stringBuilder.append(m_szBTMAC);
    }

    String m_szLongID = stringBuilder.toString();
    Log.i("utils", "手机唯一标识为:" + m_szLongID);

    MessageDigest m = null;
    try {
        m = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    m.update(m_szLongID.getBytes(), 0, m_szLongID.length());

    byte p_md5Data[] = m.digest();

    String m_szUniqueID = new String();
    for (int i = 0; i < p_md5Data.length; i++) {
        int b = (0xFF & p_md5Data[i]);

        if (b <= 0xF)
            m_szUniqueID += "0";

        m_szUniqueID += Integer.toHexString(b);
    }
    m_szUniqueID = m_szUniqueID.toUpperCase();

    Log.i("utils", "手机唯一标识MD5为:" + m_szUniqueID);
    return m_szUniqueID;
}
 
开发者ID:tututututututu,项目名称:BaseCore,代码行数:79,代码来源:PhoneUtils.java


注:本文中的android.bluetooth.BluetoothAdapter.getAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。