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


Java AdvertiseSettings.Builder方法代码示例

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


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

示例1: jsonToBleAdvertiseSettings

import android.bluetooth.le.AdvertiseSettings; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static AdvertiseSettings jsonToBleAdvertiseSettings(JSONObject jsonObject)
        throws JSONException {
    AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
    if (jsonObject.has("AdvertiseMode")) {
        int mode = MbsEnums.BLE_ADVERTISE_MODE.getInt(jsonObject.getString("AdvertiseMode"));
        builder.setAdvertiseMode(mode);
    }
    // Timeout in milliseconds.
    if (jsonObject.has("Timeout")) {
        builder.setTimeout(jsonObject.getInt("Timeout"));
    }
    if (jsonObject.has("Connectable")) {
        builder.setConnectable(jsonObject.getBoolean("Connectable"));
    }
    if (jsonObject.has("TxPowerLevel")) {
        int txPowerLevel =
                MbsEnums.BLE_ADVERTISE_TX_POWER.getInt(jsonObject.getString("TxPowerLevel"));
        builder.setTxPowerLevel(txPowerLevel);
    }
    return builder.build();
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:23,代码来源:JsonDeserializer.java

示例2: startServer

import android.bluetooth.le.AdvertiseSettings; //导入方法依赖的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

示例3: makeAdvertiseSetting

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

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

    //Set advertise mode to control the advertising power and latency.
    builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY);
    //Set advertise TX power level to control the transmission power level for the advertising.
    builder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_ULTRA_LOW);
    //Set whether the advertisement type should be connectable or non-connectable.
    builder.setConnectable(CONNECTABLE);
    //Limit advertising to a given amount of time.
    builder.setTimeout(TIMEOUT);

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

示例4: start

import android.bluetooth.le.AdvertiseSettings; //导入方法依赖的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: createAdvertiseSettings

import android.bluetooth.le.AdvertiseSettings; //导入方法依赖的package包/类
public AdvertiseSettings createAdvertiseSettings(boolean connectable, int timeoutMillis) {
    AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
    builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);
    builder.setConnectable(connectable);
    builder.setTimeout(timeoutMillis);
    builder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);
    return builder.build();
}
 
开发者ID:wooden-fishes,项目名称:IBeaconBroadcastDemo,代码行数:9,代码来源:MainActivity.java

示例6: buildAdvertiseSettings

import android.bluetooth.le.AdvertiseSettings; //导入方法依赖的package包/类
private AdvertiseSettings buildAdvertiseSettings() {
    AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
    builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_POWER);
    builder.setTimeout(0); // Advertise as long as Bluetooth is on, blatantly ignoring Google's advice.
    builder.setConnectable(false);
    return builder.build();
}
 
开发者ID:aarmea,项目名称:noise,代码行数:8,代码来源:BluetoothSyncService.java

示例7: createAdvSettings

import android.bluetooth.le.AdvertiseSettings; //导入方法依赖的package包/类
private AdvertiseSettings createAdvSettings(boolean connectable, int timeoutMillis) {
AdvertiseSettings.Builder mSettingsbuilder = new AdvertiseSettings.Builder();
mSettingsbuilder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);
mSettingsbuilder.setConnectable(connectable);
mSettingsbuilder.setTimeout(timeoutMillis);
mSettingsbuilder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);
AdvertiseSettings mAdvertiseSettings = mSettingsbuilder.build();
if(mAdvertiseSettings == null){
	if(D){
		Log.e(TAG,"mAdvertiseSettings == null");
	}
}
return mAdvertiseSettings;
}
 
开发者ID:blxble,项目名称:mesh-core-on-android,代码行数:15,代码来源:JniCallbacks.java

示例8:

import android.bluetooth.le.AdvertiseSettings; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
/*package*/ AdvertiseSettings getNativeSettings(BleAdvertisingMode mode, BleTransmissionPower power, Interval timeout) {
    AdvertiseSettings.Builder settings = new AdvertiseSettings.Builder();
    settings.setAdvertiseMode(mode.getNativeMode());
    settings.setTxPowerLevel(power.getNativeMode());
    settings.setConnectable(isConnectable());
    settings.setTimeout((int) timeout.millis());
    return settings.build();
}
 
开发者ID:AsteroidOS,项目名称:AsteroidOSSync,代码行数:10,代码来源:BleAdvertisingPacket.java

示例9: createAdvSettings

import android.bluetooth.le.AdvertiseSettings; //导入方法依赖的package包/类
private AdvertiseSettings createAdvSettings() {
    AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
    builder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);
    builder.setConnectable(true);
    builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);
    return builder.build();
}
 
开发者ID:wl1244hotmai,项目名称:BLE-Mesh,代码行数:8,代码来源:BLEPeripheral.java

示例10: createAdvSettings

import android.bluetooth.le.AdvertiseSettings; //导入方法依赖的package包/类
public static AdvertiseSettings createAdvSettings(int timeoutMillis) {
    AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
    builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);
    builder.setConnectable(true);
    builder.setTimeout(timeoutMillis);
    builder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);
    return builder.build();
}
 
开发者ID:gnu3ra,项目名称:Scatterbrain,代码行数:9,代码来源:BleUtil.java

示例11: getAdvertiseSettings

import android.bluetooth.le.AdvertiseSettings; //导入方法依赖的package包/类
@TargetApi(21)
public static AdvertiseSettings getAdvertiseSettings(boolean connectable) {
    AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
    builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_POWER);
    builder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM);
    builder.setConnectable(connectable);

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

示例12: initAdvertiseData

import android.bluetooth.le.AdvertiseSettings; //导入方法依赖的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

示例13: initAdvertiseData

import android.bluetooth.le.AdvertiseSettings; //导入方法依赖的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

示例14: startAdvertising

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