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


Java AdvertiseData类代码示例

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


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

示例1: startAdvertising

import android.bluetooth.le.AdvertiseData; //导入依赖的package包/类
private void startAdvertising() {
    if (mBluetoothLeAdvertiser == null) return;

    AdvertiseSettings settings = new AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setConnectable(true)
            .setTimeout(0)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
            .build();

    AdvertiseData data = new AdvertiseData.Builder()
            .setIncludeDeviceName(true)
            .setIncludeTxPowerLevel(false)
            .addServiceUuid(new ParcelUuid(GattProfile.SERVICE_UUID))
            .build();

    mBluetoothLeAdvertiser.startAdvertising(settings, data, mAdvertiseCallback);
}
 
开发者ID:holgi-s,项目名称:RangeThings,代码行数:19,代码来源:GattServer.java

示例2: 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

示例3: startAdvertising

import android.bluetooth.le.AdvertiseData; //导入依赖的package包/类
private void startAdvertising() {
    AdvertiseSettings advSettings = new AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
            .setConnectable(true)
            .build();

    AdvertiseData advData = new AdvertiseData.Builder()
            .setIncludeTxPowerLevel(true)
            .addServiceUuid(Constants.SERVICE_pUUID)
            .addServiceData(Constants.SERVICE_pUUID, serviceData)
            .build();

    AdvertiseData advScanResponse = new AdvertiseData.Builder()
            .setIncludeDeviceName(true)
            .build();

    if (mAdvertiser != null) {
        gattService.startAdvertising();
        mAdvertiser.startAdvertising(advSettings, advData, advScanResponse, advCallback);
        Log.d(TAG, "Started advertisement of mDL service with data " + new String(serviceData));
    } else {
        Log.e(TAG, "mAdvertiser not available!");
    }
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:26,代码来源:BLEConnection.java

示例4: 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

示例5: 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

示例6: startAdvertising

import android.bluetooth.le.AdvertiseData; //导入依赖的package包/类
private void startAdvertising() {
    BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
    mBluetoothLeAdvertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
    if (mBluetoothLeAdvertiser == null) {
        Log.w(TAG, "Failed to create advertiser");
        return;
    }

    AdvertiseSettings settings = new AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setConnectable(true)
            .setTimeout(0)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
            .build();

    AdvertiseData data = new AdvertiseData.Builder()
            .setIncludeDeviceName(true)
            .setIncludeTxPowerLevel(false)
            .addServiceUuid(new ParcelUuid(SERVICE_UUID))
            .build();

    mBluetoothLeAdvertiser
            .startAdvertising(settings, data, mAdvertiseCallback);
}
 
开发者ID:Nilhcem,项目名称:blefun-androidthings,代码行数:25,代码来源:GattServer.java

示例7: startAdvertising

import android.bluetooth.le.AdvertiseData; //导入依赖的package包/类
/**
 * Begin advertising over Bluetooth that this device is connectable
 * and supports the Current Time Service.
 */
private void startAdvertising() {
    BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
    mBluetoothLeAdvertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
    if (mBluetoothLeAdvertiser == null) {
        Log.w(TAG, "Failed to create advertiser");
        return;
    }

    AdvertiseSettings settings = new AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setConnectable(true)
            .setTimeout(0)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
            .build();

    AdvertiseData data = new AdvertiseData.Builder()
            .setIncludeDeviceName(true)
            .setIncludeTxPowerLevel(false)
            .addServiceUuid(new ParcelUuid(TimeProfile.TIME_SERVICE))
            .build();

    mBluetoothLeAdvertiser
            .startAdvertising(settings, data, mAdvertiseCallback);
}
 
开发者ID:androidthings,项目名称:sample-bluetooth-le-gattserver,代码行数:29,代码来源:GattServerActivity.java

示例8: startAdvertising

import android.bluetooth.le.AdvertiseData; //导入依赖的package包/类
private void startAdvertising() {
    if (mBluetoothLeAdvertiser == null) return;

    AdvertiseSettings settings = new AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setConnectable(true)
            .setTimeout(0)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
            .build();

    AdvertiseData data = new AdvertiseData.Builder()
            .setIncludeDeviceName(true)
            .addServiceUuid(new ParcelUuid(UARTProfile.UART_SERVICE))
            .build();

    mBluetoothLeAdvertiser.startAdvertising(settings, data, mAdvertiseCallback);
}
 
开发者ID:thejeshgn,项目名称:BleUARTPeripheral,代码行数:18,代码来源:MainActivity.java

示例9: 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

示例10: EddystoneAdvertiser

import android.bluetooth.le.AdvertiseData; //导入依赖的package包/类
/**
 * Creates an Eddystone BLE advertiser. It does not start any actual transmission.
 * @param frameData              Frame data (without service data frame type or TX power bytes)
 * @param pos                    Frame data offset
 * @param len                    Frame data size
 */
public EddystoneAdvertiser(SettingsProvider provider, byte frameType, byte[] frameData,
                           int pos, int len)
{
    super(provider);

    mServiceData = new byte[2 + len];

    mServiceData[0] = frameType;
    mServiceData[1] = FRAME_TLM == frameType ? 0
            : AdvertisersManager.getZeroDistanceTxPower(provider.getTxPowerLevel());
    System.arraycopy(frameData, pos, mServiceData, 2, len);

    // an advertisement packet can have at most 31 bytes
    mAdvertiseData = new AdvertiseData.Builder()
            .setIncludeDeviceName(false)
            .setIncludeTxPowerLevel(false)
            .addServiceData(EDDYSTONE_SERVICE_UUID, mServiceData)
            .addServiceUuid(EDDYSTONE_SERVICE_UUID)
            .build();

    if (provider.isConnectable()) {
        mAdvertiseScanResponse = new AdvertiseData.Builder()
                .setIncludeDeviceName(true)
                .setIncludeTxPowerLevel(false)  // allows 3 more bytes for device name
                .addServiceUuid(new ParcelUuid(EddystoneGattService.UUID_EDDYSTONE_GATT_SERVICE))
                .build();
    }
}
 
开发者ID:adriancretu,项目名称:beacons-android,代码行数:35,代码来源:EddystoneAdvertiser.java

示例11: 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

示例12: getFatBeaconAdvertisementData

import android.bluetooth.le.AdvertiseData; //导入依赖的package包/类
@TargetApi(21)
public static AdvertiseData getFatBeaconAdvertisementData(byte[] fatBeaconAdvertisement) {

  // Manually build the advertising info
  int length = Math.min(fatBeaconAdvertisement.length, 17);
  byte[] beaconData = new byte[length + 3];
  System.arraycopy(fatBeaconAdvertisement, 0, beaconData, 3, length);
  beaconData[0] = URL_FRAME_TYPE;
  beaconData[1] = (byte) 0xBA;
  beaconData[2] = FAT_BEACON;
  return new AdvertiseData.Builder()
      .setIncludeTxPowerLevel(false) // reserve advertising space for URI
      .addServiceData(EDDYSTONE_BEACON_UUID, beaconData)
      // Adding 0xFEAA to the "Service Complete List UUID 16" (0x3) for iOS compatibility
      .addServiceUuid(EDDYSTONE_BEACON_UUID)
      .build();
}
 
开发者ID:google,项目名称:physical-web,代码行数:18,代码来源:AdvertiseDataUtils.java

示例13: BTEndPoint

import android.bluetooth.le.AdvertiseData; //导入依赖的package包/类
public BTEndPoint(String id, String content, String details) {
    super(id);
    this.content = content;
    this.details = details;
    this.type=this.getClass().getSimpleName();
    AdvertiseData data;
}
 
开发者ID:talCrafts,项目名称:Udhari,代码行数:8,代码来源:BTEndPoint.java

示例14: 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

示例15: 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


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