本文整理汇总了Java中android.bluetooth.le.AdvertiseSettings类的典型用法代码示例。如果您正苦于以下问题:Java AdvertiseSettings类的具体用法?Java AdvertiseSettings怎么用?Java AdvertiseSettings使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AdvertiseSettings类属于android.bluetooth.le包,在下文中一共展示了AdvertiseSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startAdvertising
import android.bluetooth.le.AdvertiseSettings; //导入依赖的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!");
}
}
示例2: startAdvertising
import android.bluetooth.le.AdvertiseSettings; //导入依赖的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);
}
示例3: 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();
}
示例4: 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;
}
示例5: startAdvertising
import android.bluetooth.le.AdvertiseSettings; //导入依赖的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);
}
示例6: startAdvertising
import android.bluetooth.le.AdvertiseSettings; //导入依赖的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);
}
示例7: 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();
}
示例8: startAdvertising
import android.bluetooth.le.AdvertiseSettings; //导入依赖的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);
}
示例9: 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);
}
示例10: broadcastAsBeacon
import android.bluetooth.le.AdvertiseSettings; //导入依赖的package包/类
public void broadcastAsBeacon() {
Beacon beacon = new Beacon.Builder()
.setId1("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6")
.setId2("1")
.setId3("2")
.setManufacturer(0x0118) // Radius Networks. Change this for other beacon layouts
.setTxPower(-59)
.setDataFields(Arrays.asList(new Long[]{0l})) // Remove this for beacon layouts without d: fields
.build();
// Change the layout below for other beacon types
BeaconParser beaconParser = new BeaconParser()
.setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
BeaconTransmitter beaconTransmitter = new BeaconTransmitter(context, beaconParser);
beaconTransmitter.startAdvertising(beacon, new AdvertiseCallback() {
@Override
public void onStartFailure(int errorCode) {
Log.e("Class", "Advertisement start failed with code: " + errorCode);
}
@Override
public void onStartSuccess(AdvertiseSettings settingsInEffect) {
Log.i("class", "Advertisement start succeeded.");
}
});
}
示例11: setAdvertiseInterval
import android.bluetooth.le.AdvertiseSettings; //导入依赖的package包/类
@SuppressLint("InlinedApi")
@Override
public int setAdvertiseInterval(int advertiseIntervalMs) {
Util.log(TAG, "setAdvertiseInterval() called with: advertiseIntervalMs = [" + advertiseIntervalMs + "]");
@Advertiser.Mode int mode;
if (advertiseIntervalMs <= 100 + (250 - 100) / 2) {
// 100 ms
mode = AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY;
} else if (advertiseIntervalMs >= 1000 - (1000 - 250) / 2) {
// 1000 ms
mode = AdvertiseSettings.ADVERTISE_MODE_LOW_POWER;
} else {
// 250 ms actually
mode = AdvertiseSettings.ADVERTISE_MODE_BALANCED;
}
if (mode != getModifiedOrOriginalBeacon().getAdvertiseMode()) {
// restarting a beacon destroys the GATT connection, make sure we use a stopped clone
getOrCloneConfiguredBeacon().edit().setAdvertiseMode(mode).apply();
}
return getAdvertiseInterval();
}
示例12: setToAdvertising
import android.bluetooth.le.AdvertiseSettings; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void setToAdvertising(BleManager mgr, final AdvertiseSettings settings, L_Util.AdvertisingCallback callback, Interval delay)
{
if (Utils.isLollipop())
{
L_UtilBridge.setAdvListener(callback);
mgr.getPostManager().postToUpdateThreadDelayed(new Runnable()
{
@Override
public void run()
{
L_Util.getNativeAdvertisingCallback().onStartSuccess(settings);
}
}, delay.millis());
}
}
示例13: 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();
}
示例14: onStartSuccess
import android.bluetooth.le.AdvertiseSettings; //导入依赖的package包/类
public void onStartSuccess(android.bluetooth.le.AdvertiseSettings settingsInEffect) {
if (settingsInEffect != null) {
Log.d("debug", "onStartSuccess TxPowerLv="
+ settingsInEffect.getTxPowerLevel()
+ " mode=" + settingsInEffect.getMode()
+ " timeout=" + settingsInEffect.getTimeout());
} else {
Log.d("debug", "onStartSuccess, settingInEffect is null");
}
switchView.setChecked(true);
setProgressBarIndeterminateVisibility(false);
}
示例15: serializeBleAdvertisingSettings
import android.bluetooth.le.AdvertiseSettings; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Bundle serializeBleAdvertisingSettings(AdvertiseSettings advertiseSettings) {
Bundle result = new Bundle();
result.putString(
"TxPowerLevel",
MbsEnums.BLE_ADVERTISE_TX_POWER.getString(advertiseSettings.getTxPowerLevel()));
result.putString(
"Mode", MbsEnums.BLE_ADVERTISE_MODE.getString(advertiseSettings.getMode()));
result.putInt("Timeout", advertiseSettings.getTimeout());
result.putBoolean("IsConnectable", advertiseSettings.isConnectable());
return result;
}