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