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


Java AdvertiseData.Builder方法代码示例

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


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

示例1: for

import android.bluetooth.le.AdvertiseData; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
/*package*/ AdvertiseData getNativeData() {
    AdvertiseData.Builder data = new AdvertiseData.Builder();
    for (UUID id : serviceUuids)
    {
        data.addServiceUuid(new ParcelUuid(id));
    }
    if (m_manufacturerId != 0 && m_manData != null)
    {
        data.addManufacturerData(m_manufacturerId, m_manData);
    }
    if (serviceData != null && serviceData.size() > 0)
    {
        for (UUID dataUuid : serviceData.keySet())
        {
            data.addServiceData(new ParcelUuid(dataUuid), serviceData.get(dataUuid));
        }
    }
    data.setIncludeDeviceName(includeDeviceName());
    data.setIncludeTxPowerLevel(includeTxPowerLevel());
    return data.build();
}
 
开发者ID:iDevicesInc,项目名称:SweetBlue,代码行数:23,代码来源:BleAdvertisingPacket.java

示例2: createAdvertiseData

import android.bluetooth.le.AdvertiseData; //导入方法依赖的package包/类
public AdvertiseData createAdvertiseData(UUID proximityUuid, int major,
                                         int minor, byte txPower) {
    if (proximityUuid == null) {
        throw new IllegalArgumentException("proximitiUuid null");
    }
    byte[] manufacturerData = new byte[23];
    ByteBuffer bb = ByteBuffer.wrap(manufacturerData);
    bb.order(ByteOrder.BIG_ENDIAN);
    bb.put((byte) 0x02);
    bb.put((byte) 0x15);
    bb.putLong(proximityUuid.getMostSignificantBits());
    bb.putLong(proximityUuid.getLeastSignificantBits());
    bb.putShort((short) major);
    bb.putShort((short) minor);
    bb.put(txPower);

    AdvertiseData.Builder builder = new AdvertiseData.Builder();
    builder.addManufacturerData(0x004c, manufacturerData);
    AdvertiseData adv = builder.build();
    return adv;
}
 
开发者ID:wooden-fishes,项目名称:IBeaconBroadcastDemo,代码行数:22,代码来源:MainActivity.java

示例3: startServer

import android.bluetooth.le.AdvertiseData; //导入方法依赖的package包/类
public BtError startServer(){
	BtError error = checkBluetooth();
	if(error != BtError.None)
		return error;
	bleAdvertiser = btAdapter.getBluetoothLeAdvertiser();
	gattServer = btManager.openGattServer(context, gattServerCallback);
	for(BluetoothGattService service : services){
		gattServer.addService(service);
	}
	if(bleAdvertiser == null)
		return BtError.NoServer;
	AdvertiseSettings.Builder settings = new AdvertiseSettings.Builder();
	settings.setAdvertiseMode(advertiseMode);
	settings.setConnectable(true);
	settings.setTimeout(0);
	settings.setTxPowerLevel(advertiseTransmitPower);
	AdvertiseData.Builder data = new AdvertiseData.Builder();
	data.setIncludeDeviceName(advertiseDeviceName);
	//data.addServiceUuid(new ParcelUuid(SERVICE_COMMUNICATION));
	bleAdvertiser.startAdvertising(settings.build(), data.build(), advertiseCallback);
	serverRunning = true;
	return BtError.None;
}
 
开发者ID:MB3hel,项目名称:Quick-Bluetooth-LE,代码行数:24,代码来源:BLEServer.java

示例4: start

import android.bluetooth.le.AdvertiseData; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void start(String uuidString) {
    mServiceUUID = UUID.fromString(uuidString);
    if (mBtAdvertiser == null) {
        return;
    }

    BluetoothGattService btGattService = new BluetoothGattService(mServiceUUID, BluetoothGattService.SERVICE_TYPE_PRIMARY);
    btGattService.addCharacteristic(mBtGattCharacteristic);
    BluetoothGattServerCallback btGattServerCallback = createGattServerCallback(mServiceUUID, UUID.fromString(CHARACTERISTIC_UUID));
    mBtGattServer = mBtManager.openGattServer(mActivity.getApplicationContext(), btGattServerCallback);
    mBtGattServer.addService(btGattService);

    mDataBuilder = new AdvertiseData.Builder();
    mDataBuilder.setIncludeTxPowerLevel(false);
    mDataBuilder.addServiceUuid(new ParcelUuid(mServiceUUID));

    mSettingsBuilder=new AdvertiseSettings.Builder();
    mSettingsBuilder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);
    mSettingsBuilder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);

    mBleAdvertiser = mBtAdapter.getBluetoothLeAdvertiser();
    mBleAdvertiser.startAdvertising(mSettingsBuilder.build(), mDataBuilder.build(), mAdvertiseCallback);
}
 
开发者ID:seiji,项目名称:unity-bluetooth,代码行数:26,代码来源:BLEServicePeripheral.java

示例5: getAdvertisementData

import android.bluetooth.le.AdvertiseData; //导入方法依赖的package包/类
@TargetApi(21)
public static AdvertiseData getAdvertisementData(byte[] urlData) {
  AdvertiseData.Builder builder = new AdvertiseData.Builder();
  builder.setIncludeTxPowerLevel(false); // reserve advertising space for URI

  // Manually build the advertising info
  // See https://github.com/google/eddystone/tree/master/eddystone-url
  if (urlData == null || urlData.length == 0) {
    return null;
  }

  byte[] beaconData = new byte[urlData.length + 2];
  System.arraycopy(urlData, 0, beaconData, 2, urlData.length);
  beaconData[0] = URL_FRAME_TYPE; // frame type: url
  beaconData[1] = (byte) 0xBA; // calibrated tx power at 0 m

  builder.addServiceData(EDDYSTONE_BEACON_UUID, beaconData);

  // Adding 0xFEAA to the "Service Complete List UUID 16" (0x3) for iOS compatibility
  builder.addServiceUuid(EDDYSTONE_BEACON_UUID);

  return builder.build();
}
 
开发者ID:google,项目名称:physical-web,代码行数:24,代码来源:AdvertiseDataUtils.java

示例6: jsonToBleAdvertiseData

import android.bluetooth.le.AdvertiseData; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static AdvertiseData jsonToBleAdvertiseData(JSONObject jsonObject) throws JSONException {
    AdvertiseData.Builder builder = new AdvertiseData.Builder();
    if (jsonObject.has("IncludeDeviceName")) {
        builder.setIncludeDeviceName(jsonObject.getBoolean("IncludeDeviceName"));
    }
    if (jsonObject.has("IncludeTxPowerLevel")) {
        builder.setIncludeTxPowerLevel(jsonObject.getBoolean("IncludeTxPowerLevel"));
    }
    if (jsonObject.has("ServiceData")) {
        JSONArray serviceData = jsonObject.getJSONArray("ServiceData");
        for (int i = 0; i < serviceData.length(); i++) {
            JSONObject dataSet = serviceData.getJSONObject(i);
            ParcelUuid parcelUuid = ParcelUuid.fromString(dataSet.getString("UUID"));
            builder.addServiceUuid(parcelUuid);
            if (dataSet.has("Data")) {
                byte[] data = Base64.decode(dataSet.getString("Data"), Base64.DEFAULT);
                builder.addServiceData(parcelUuid, data);
            }
        }
    }
    if (jsonObject.has("ManufacturerData")) {
        JSONObject manufacturerData = jsonObject.getJSONObject("ManufacturerData");
        int manufacturerId = manufacturerData.getInt("ManufacturerId");
        byte[] manufacturerSpecificData =
                Base64.decode(jsonObject.getString("ManufacturerSpecificData"), Base64.DEFAULT);
        builder.addManufacturerData(manufacturerId, manufacturerSpecificData);
    }
    return builder.build();
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:31,代码来源:JsonDeserializer.java

示例7: buildAdvertiseData

import android.bluetooth.le.AdvertiseData; //导入方法依赖的package包/类
private AdvertiseData buildAdvertiseData() {
    AdvertiseData.Builder builder = new AdvertiseData.Builder();

    // We are including this device's physical MAC address in the advertisement to enable higher bandwidth pair-free communication over Bluetooth Classic sockets.
    // While our communications will always be anonymous by design, this still has privacy implications:
    // If an attacker manages to associate an address with a person, they will be able to determine if that person is nearby as long as the app is installed on that phone.
    builder.addServiceUuid(new ParcelUuid(serviceUuidAndAddress));
    // TODO: Include some portion of the sync bit string/Bloom filter from the database
    builder.setIncludeDeviceName(false);
    return builder.build();
}
 
开发者ID:aarmea,项目名称:noise,代码行数:12,代码来源:BluetoothSyncService.java

示例8: createAdvertiseData

import android.bluetooth.le.AdvertiseData; //导入方法依赖的package包/类
private AdvertiseData createAdvertiseData(ParcelUuid uuid, byte[] serviceData){		 
	AdvertiseData.Builder mDataBuilder = new AdvertiseData.Builder();
	mDataBuilder.addServiceUuid(uuid);
mDataBuilder.addServiceData(uuid, serviceData);
AdvertiseData mAdvertiseData = mDataBuilder.build();

if(mAdvertiseData==null){
	Log.e(TAG, "mAdvertiseSettings == null");
}
return mAdvertiseData;
  }
 
开发者ID:blxble,项目名称:mesh-core-on-android,代码行数:12,代码来源:JniCallbacks.java

示例9: makeAdvertiseData

import android.bluetooth.le.AdvertiseData; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private AdvertiseData makeAdvertiseData() {

    AdvertiseData.Builder builder = new AdvertiseData.Builder();
    //加入自定的service uuid
    builder.addServiceUuid(new ParcelUuid(UUID.fromString(SERVICE_UUID)));

    //設定用device name顯示為ble的local name
    builder.setIncludeDeviceName(true);

    return builder.build();
}
 
开发者ID:RayTW,项目名称:BLEServerSimple,代码行数:13,代码来源:AdvertiseAdaptor.java

示例10: createAdvData

import android.bluetooth.le.AdvertiseData; //导入方法依赖的package包/类
private AdvertiseData createAdvData() {
        AdvertiseData.Builder builder = new AdvertiseData.Builder();
        builder.addServiceUuid(new ParcelUuid(serviceUUID));
        builder.setIncludeTxPowerLevel(false);
//        builder.setManufacturerData(0x1234578, manufacturerData);
        return builder.build();
    }
 
开发者ID:wl1244hotmai,项目名称:BLE-Mesh,代码行数:8,代码来源:BLEPeripheral.java

示例11: advertise

import android.bluetooth.le.AdvertiseData; //导入方法依赖的package包/类
private void advertise() throws ExpressionParseException {
    final BluetoothLeAdvertiser bleAdvertiser = btAdapter.getBluetoothLeAdvertiser();
    AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder().setIncludeDeviceName(true);

    for(Map.Entry<String, String> expressionEntry : registeredExpressions.entrySet()) {
        SensorValueExpression svExpression = (SensorValueExpression) ExpressionFactory.parse(expressionEntry.getValue());
        String sensorValuePath = svExpression.getEntity() + ":" + svExpression.getValuePath();
        UUID serviceUuid = getUuidForSensorValuePath(sensorValuePath);
        dataBuilder.addServiceUuid(new ParcelUuid(serviceUuid));
    }

    bleAdvertiser.startAdvertising(advertiseSettings, dataBuilder.build(), advertisingCallback);
}
 
开发者ID:swandroid,项目名称:swan-sense-studio,代码行数:14,代码来源:BLEManager.java

示例12: makeAdvertiseData

import android.bluetooth.le.AdvertiseData; //导入方法依赖的package包/类
public static AdvertiseData makeAdvertiseData(String message) {
    while (message.length() < 9)
    {
        message += " ";
    }
    byte[] data = message.substring(2).getBytes();
    ParcelUuid pu = ParcelUuid.fromString("0000" + asHex(message.substring(0,2).getBytes()) + "-0000-1000-8000-00805F9B34FB");
    AdvertiseData.Builder builder = new AdvertiseData.Builder();
    builder.addServiceData(pu, data);
    builder.addServiceUuid(pu);

    return builder.build();
}
 
开发者ID:gnu3ra,项目名称:Scatterbrain,代码行数:14,代码来源:BleUtil.java

示例13: initAdvertiseData

import android.bluetooth.le.AdvertiseData; //导入方法依赖的package包/类
private void initAdvertiseData() {
    //初始化Advertise的设定
    Context mContext = contextWeakReference.get();
    if (mContext == null) {
        prepared = false;
        return;
    }
    BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
    BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
    advertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
    advertiseCallback = new AdvertiseCallback() {
        @Override
        public void onStartSuccess(AdvertiseSettings settingsInEffect) {
            super.onStartSuccess(settingsInEffect);
            Log.d(TAG, "["+
                    Thread.currentThread().getStackTrace()[2].getFileName() + "_" +
                    Thread.currentThread().getStackTrace()[2].getLineNumber() + "_" +
                    Thread.currentThread().getStackTrace()[2].getMethodName() + "]");
            Log.i(TAG, "onStartSuccess success");

            advertiseResultListener.onAdvertiseSuccess();

            if (settingsInEffect != null) {
                Log.d(TAG, "onStartSuccess TxPowerLv=" + settingsInEffect.getTxPowerLevel() + " mode=" + settingsInEffect.getMode()
                        + " timeout=" + settingsInEffect.getTimeout());
            } else {
                Log.e(TAG, "onStartSuccess, settingInEffect is null");
            }
            Log.i(TAG, "onStartSuccess settingsInEffect" + settingsInEffect);
        }

        @Override
        public void onStartFailure(int errorCode) {
            super.onStartFailure(errorCode);
            Log.e(TAG, "Advertise failed.Error code: " + errorCode);
            advertiseResultListener.onAdvertiseFailed(errorCode);
        }
    };
    AdvertiseSettings.Builder settingsBuilder = new AdvertiseSettings.Builder();
    settingsBuilder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY);//ADVERTISE_MODE_BALANCED origin
    settingsBuilder.setConnectable(true);
    settingsBuilder.setTimeout(0);
    settingsBuilder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);// ADVERTISE_TX_POWER_MEDIUM origin
    advertiseSettings = settingsBuilder.build();
    AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
    dataBuilder.setIncludeDeviceName(true);
    dataBuilder.addServiceUuid(ParcelUuid.fromString(BLEProfile.UUID_SERVICE));
    advertiseData = dataBuilder.build();
    prepared = true;
}
 
开发者ID:AnXi-TieGuanYin-Tea,项目名称:AndroidBluttoothMasterAndSlave,代码行数:51,代码来源:BLEAdvertiser.java

示例14: initAdvertiseData

import android.bluetooth.le.AdvertiseData; //导入方法依赖的package包/类
private void initAdvertiseData() {
    //初始化Advertise的设定
    Context mContext = contextWeakReference.get();
    if (mContext == null) {
        prepared = false;
        return;
    }
    BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
    BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
    advertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
    advertiseCallback = new AdvertiseCallback() {
        @Override
        public void onStartSuccess(AdvertiseSettings settingsInEffect) {
            super.onStartSuccess(settingsInEffect);
            Log.i(TAG, "Advertise success");

            advertiseResultListener.onAdvertiseSuccess();

            if (settingsInEffect != null) {
                Log.d(TAG, "onStartSuccess TxPowerLv=" + settingsInEffect.getTxPowerLevel() + " mode=" + settingsInEffect.getMode()
                        + " timeout=" + settingsInEffect.getTimeout());
            } else {
                Log.e(TAG, "onStartSuccess, settingInEffect is null");
            }
            Log.i(TAG, "onStartSuccess settingsInEffect" + settingsInEffect);
        }

        @Override
        public void onStartFailure(int errorCode) {
            super.onStartFailure(errorCode);
            Log.e(TAG, "Advertise failed.Error code: " + errorCode);
            advertiseResultListener.onAdvertiseFailed(errorCode);
        }
    };
    AdvertiseSettings.Builder settingsBuilder = new AdvertiseSettings.Builder();
    settingsBuilder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);
    settingsBuilder.setConnectable(true);
    settingsBuilder.setTimeout(0);
    settingsBuilder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM);
    advertiseSettings = settingsBuilder.build();
    AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
    dataBuilder.setIncludeDeviceName(true);
    dataBuilder.addServiceUuid(ParcelUuid.fromString(BLEProfile.UUID_SERVICE));
    advertiseData = dataBuilder.build();
    prepared = true;
}
 
开发者ID:czvn,项目名称:Android-BLE-Library,代码行数:47,代码来源:BLEAdvertiser.java

示例15: startAdvertising

import android.bluetooth.le.AdvertiseData; //导入方法依赖的package包/类
/**
 * Starts this beacon advertising
 */
public void startAdvertising() {
    if (mBeacon == null) {
        throw new NullPointerException("Beacon cannot be null.  Set beacon before starting advertising");
    }
    int manufacturerCode = mBeacon.getManufacturer();
    int serviceUuid = -1;
    if (mBeaconParser.getServiceUuid() != null) {
        serviceUuid = mBeaconParser.getServiceUuid().intValue();
    }

    if (mBeaconParser == null) {
        throw new NullPointerException("You must supply a BeaconParser instance to BeaconTransmitter.");
    }

    byte[] advertisingBytes = mBeaconParser.getBeaconAdvertisementData(mBeacon);
    String byteString = "";
    for (int i= 0; i < advertisingBytes.length; i++) {
        byteString += String.format("%02X", advertisingBytes[i]);
        byteString += " ";
    }
    LogManager.d(TAG, "Starting advertising with ID1: %s ID2: %s ID3: %s and data: %s of size "
                    + "%s", mBeacon.getId1(),
                    mBeacon.getIdentifiers().size() > 1 ? mBeacon.getId2() : "",
                    mBeacon.getIdentifiers().size() > 2 ? mBeacon.getId3() : "", byteString,
            advertisingBytes.length);

    try{
        AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
        if (serviceUuid > 0) {
            byte[] serviceUuidBytes = new byte[] {
                    (byte) (serviceUuid & 0xff),
                    (byte) ((serviceUuid >> 8) & 0xff)};
            ParcelUuid parcelUuid = parseUuidFrom(serviceUuidBytes);
            dataBuilder.addServiceData(parcelUuid, advertisingBytes);
            dataBuilder.addServiceUuid(parcelUuid);
            dataBuilder.setIncludeTxPowerLevel(false);
            dataBuilder.setIncludeDeviceName(false);

        } else {
            dataBuilder.addManufacturerData(manufacturerCode, advertisingBytes);
        }

        AdvertiseSettings.Builder settingsBuilder = new AdvertiseSettings.Builder();

        settingsBuilder.setAdvertiseMode(mAdvertiseMode);
        settingsBuilder.setTxPowerLevel(mAdvertiseTxPowerLevel);
        settingsBuilder.setConnectable(false);

        mBluetoothLeAdvertiser.startAdvertising(settingsBuilder.build(), dataBuilder.build(), getAdvertiseCallback());
        LogManager.d(TAG, "Started advertisement with callback: %s", getAdvertiseCallback());

    } catch (Exception e){
        LogManager.e(e, TAG, "Cannot start advertising due to exception");
    }
}
 
开发者ID:AltBeacon,项目名称:android-beacon-library,代码行数:59,代码来源:BeaconTransmitter.java


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