本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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");
}
}