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


Java AdvertiseCallback类代码示例

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


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

示例1: broadcastAsBeacon

import android.bluetooth.le.AdvertiseCallback; //导入依赖的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.");
            }
        });
    }
 
开发者ID:MycroftAI,项目名称:Mycroft-Android,代码行数:27,代码来源:BeaconUtil.java

示例2: onStop

import android.bluetooth.le.AdvertiseCallback; //导入依赖的package包/类
@Override
public void onStop() {
    if (bluetoothGattServer != null) {
        bluetoothGattServer.clearServices();
        bluetoothGattServer.close();
        bluetoothGattServer = null;
    }

    if (bluetoothLeAdvertiseCallbacks != null) {
        if (bluetoothAdapter != null) {
            for (AdvertiseCallback callback : bluetoothLeAdvertiseCallbacks) {
                bluetoothAdapter.getBluetoothLeAdvertiser().stopAdvertising(callback);
            }
        }
        bluetoothLeAdvertiseCallbacks.clear();
    }

    connectedDevices.clear();
}
 
开发者ID:coinblesk,项目名称:coinblesk-client-gui,代码行数:20,代码来源:BluetoothLEServer.java

示例3: stopAdvertising

import android.bluetooth.le.AdvertiseCallback; //导入依赖的package包/类
@Override
public final void stopAdvertising(AdvertiseCallback callback)
{
    final BluetoothLeAdvertiser ad = L_Util.getBluetoothLeAdvertiser(m_adaptor);
    if (ad != null)
    {
        ad.stopAdvertising(callback);
    }
    else
    {
        m_bleManager.getLogger().e("Tried to stop advertising, but the BluetoothLeAdvertiser was null!");
    }
}
 
开发者ID:AsteroidOS,项目名称:AsteroidOSSync,代码行数:14,代码来源:P_AndroidBluetoothManager.java

示例4: bleStopAdvertising

import android.bluetooth.le.AdvertiseCallback; //导入依赖的package包/类
/**
 * Stop a BLE advertising.
 *
 * @param callbackId The callbackId corresponding to the {@link
 *     BluetoothLeAdvertiserSnippet#bleStartAdvertising} call that started the advertising.
 * @throws BluetoothLeScannerSnippet.BluetoothLeScanSnippetException
 */
@RpcMinSdk(Build.VERSION_CODES.LOLLIPOP_MR1)
@Rpc(description = "Stop BLE advertising.")
public void bleStopAdvertising(String callbackId) throws BluetoothLeAdvertiserSnippetException {
    AdvertiseCallback callback = mAdvertiseCallbacks.remove(callbackId);
    if (callback == null) {
        throw new BluetoothLeAdvertiserSnippetException(
                "No advertising session found for ID " + callbackId);
    }
    mAdvertiser.stopAdvertising(callback);
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:18,代码来源:BluetoothLeAdvertiserSnippet.java

示例5: shutdown

import android.bluetooth.le.AdvertiseCallback; //导入依赖的package包/类
@Override
public void shutdown() {
    for (AdvertiseCallback callback : mAdvertiseCallbacks.values()) {
        mAdvertiser.stopAdvertising(callback);
    }
    mAdvertiseCallbacks.clear();
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:8,代码来源:BluetoothLeAdvertiserSnippet.java

示例6: startSharedAdvertisingBeaconWithString

import android.bluetooth.le.AdvertiseCallback; //导入依赖的package包/类
@ReactMethod
public void startSharedAdvertisingBeaconWithString(String uuid, int major, int minor,String identifier) {
int manufacturer = 0x4C;
Beacon beacon = new Beacon.Builder()
		.setId1(uuid)
		.setId2(String.valueOf(major))
		.setId3(String.valueOf(minor))
		.setManufacturer(manufacturer)
		.setBluetoothName(identifier)
		.setTxPower(-59)
		.build();
BeaconParser beaconParser = new BeaconParser()
		.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
this.beaconTransmitter = new BeaconTransmitter(context, beaconParser);
this.beaconTransmitter.startAdvertising(beacon, new AdvertiseCallback() {

	@Override
	public void onStartFailure(int errorCode) {
		Log.d("ReactNative", "Error from start advertising " + errorCode);
	}

	@Override
	public void onStartSuccess(AdvertiseSettings settingsInEffect) {
		Log.d("ReactNative", "Success start advertising");
	}
});
}
 
开发者ID:williamtran29,项目名称:react-native-ibeacon-simulator,代码行数:28,代码来源:BeaconBroadcast.java

示例7: startAdvertisingService

import android.bluetooth.le.AdvertiseCallback; //导入依赖的package包/类
private void startAdvertisingService(final UUID uuid) {
    if (bluetoothLeAdvertiseCallbacks == null) {
        bluetoothLeAdvertiseCallbacks = new ArrayList<>();
    }

    AdvertiseCallback advertiseCallback = new AdvertiseCallback() {
        @Override
        public void onStartSuccess(AdvertiseSettings settingsInEffect) {
            Log.d(TAG, "BLE advertising - uuid: " + uuid.toString()
                    + " - onStartSuccess - settings: " + settingsInEffect.toString());
        }

        @Override
        public void onStartFailure(int errorCode) {
            Log.w(TAG, "BLE advertising - uuid: " + uuid.toString()
                    + " - onStartFailure - errorCode=" + errorCode);
        }
    };
    bluetoothLeAdvertiseCallbacks.add(advertiseCallback);

    bluetoothAdapter.getBluetoothLeAdvertiser().startAdvertising(
            new AdvertiseSettings.Builder()
                    .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
                    .setConnectable(true)
                    .setTimeout(0)
                    .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
                    .build(),
            new AdvertiseData.Builder()
                    .setIncludeDeviceName(false)
                    .addServiceUuid(new ParcelUuid(uuid))
                    .build(),
            advertiseCallback
    );
}
 
开发者ID:coinblesk,项目名称:coinblesk-client-gui,代码行数:35,代码来源:BluetoothLEServer.java

示例8: startAdvertising

import android.bluetooth.le.AdvertiseCallback; //导入依赖的package包/类
@Override
public final void startAdvertising(AdvertiseSettings settings, AdvertiseData adData, AdvertiseCallback callback)
{
    final BluetoothLeAdvertiser ad = L_Util.getBluetoothLeAdvertiser(m_adaptor);
    if (ad != null)
    {
        ad.startAdvertising(settings, adData, callback);
    }
    else
    {
        m_bleManager.getLogger().e("Tried to start advertising, but the BluetoothLeAdvertiser was null!");
    }
}
 
开发者ID:AsteroidOS,项目名称:AsteroidOSSync,代码行数:14,代码来源:P_AndroidBluetoothManager.java

示例9: startBeaconAdvertiser

import android.bluetooth.le.AdvertiseCallback; //导入依赖的package包/类
/**
 * Start or restart the advertising of an item's BLE beacon.
 * @param beacon    The item to (re)start.
 * @return True if the beacon was started, false otherwise.
 */
public boolean startBeaconAdvertiser(Beacon beacon) {
    if (null == mAdvertisersManager) {
        return false;
    }

    if (!mAdvertisersManager.isBluetoothEnabled()) {
        return false;
    }

    if (!mAdvertisersManager.canAdvertise()) {
        beacon.onAdvertiseFailed(AdvertiseCallback.ADVERTISE_FAILED_FEATURE_UNSUPPORTED);
        broadcastBeaconEvent(EVENT_ADVERTISE_UNSUPPORTED, beacon);
        return false;
    }

    // stop current advertiser for this beacon
    Advertiser existingAdvertiser = beacon.getAdvertiser();
    if (null != existingAdvertiser) {
        mAdvertisersManager.stopAdvertiser(existingAdvertiser);
        mEstimatedPDUCount += existingAdvertiser.clearPDUCount();
    }

    Advertiser advertiser = beacon.recreateAdvertiser(this);
    if (null != advertiser) {
        advertiser.setManager(mAdvertisersManager);
    }

    return null != advertiser && mAdvertisersManager.startAdvertiser(advertiser);
}
 
开发者ID:adriancretu,项目名称:beacons-android,代码行数:35,代码来源:BleService.java

示例10: onAdvertiseFailed

import android.bluetooth.le.AdvertiseCallback; //导入依赖的package包/类
public void onAdvertiseFailed(int errorCode) {
    if (AdvertiseCallback.ADVERTISE_FAILED_TOO_MANY_ADVERTISERS == errorCode){
        // user may attempt to start the beacon again when we get a free slot
        pause();
    }
    else {
        // fatal, no point in keeping the beacon in active state
        stop();
    }

    mAdvertiser = null;
    mErrorCode = errorCode;
    setErrorDetails(Advertiser.getErrorName(errorCode));
}
 
开发者ID:adriancretu,项目名称:beacons-android,代码行数:15,代码来源:Beacon.java

示例11: bleStartAdvertising

import android.bluetooth.le.AdvertiseCallback; //导入依赖的package包/类
/**
 * Start Bluetooth LE advertising.
 *
 * <p>This can be called multiple times, and each call is associated with a {@link
 * AdvertiseCallback} object, which is used to stop the advertising.
 *
 * @param callbackId
 * @param advertiseSettings A JSONObject representing a {@link AdvertiseSettings object}. E.g.
 *     <pre>
 *          {
 *            "AdvertiseMode": "ADVERTISE_MODE_BALANCED",
 *            "Timeout": (int, milliseconds),
 *            "Connectable": (bool),
 *            "TxPowerLevel": "ADVERTISE_TX_POWER_LOW"
 *          }
 *     </pre>
 *
 * @param advertiseData A JSONObject representing a {@link AdvertiseData} object. E.g.
 *     <pre>
 *          {
 *            "IncludeDeviceName": (bool),
 *            # JSON list, each element representing a set of service data, which is composed of
 *            # a UUID, and an optional string.
 *            "ServiceData": [
 *                      {
 *                        "UUID": (A string representation of {@link ParcelUuid}),
 *                        "Data": (Optional, The string representation of what you want to
 *                                 advertise, base64 encoded)
 *                        # If you want to add a UUID without data, simply omit the "Data"
 *                        # field.
 *                      }
 *                ]
 *          }
 *     </pre>
 *
 * @throws BluetoothLeAdvertiserSnippetException
 * @throws JSONException
 */
@RpcMinSdk(Build.VERSION_CODES.LOLLIPOP_MR1)
@AsyncRpc(description = "Start BLE advertising.")
public void bleStartAdvertising(
        String callbackId, JSONObject advertiseSettings, JSONObject advertiseData)
        throws BluetoothLeAdvertiserSnippetException, JSONException {
    if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) {
        throw new BluetoothLeAdvertiserSnippetException(
                "Bluetooth is disabled, cannot start BLE advertising.");
    }
    AdvertiseSettings settings = JsonDeserializer.jsonToBleAdvertiseSettings(advertiseSettings);
    AdvertiseData data = JsonDeserializer.jsonToBleAdvertiseData(advertiseData);
    AdvertiseCallback advertiseCallback = new DefaultAdvertiseCallback(callbackId);
    mAdvertiser.startAdvertising(settings, data, advertiseCallback);
    mAdvertiseCallbacks.put(callbackId, advertiseCallback);
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:54,代码来源:BluetoothLeAdvertiserSnippet.java

示例12: startAdvertising

import android.bluetooth.le.AdvertiseCallback; //导入依赖的package包/类
@Override
public void startAdvertising(AdvertiseSettings settings, AdvertiseData adData, AdvertiseCallback callback)
{
}
 
开发者ID:AsteroidOS,项目名称:AsteroidOSSync,代码行数:5,代码来源:UnitTestManagerLayer.java

示例13: stopAdvertising

import android.bluetooth.le.AdvertiseCallback; //导入依赖的package包/类
@Override
public void stopAdvertising(AdvertiseCallback callback)
{
}
 
开发者ID:AsteroidOS,项目名称:AsteroidOSSync,代码行数:5,代码来源:UnitTestManagerLayer.java

示例14: initAdvertiseData

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

示例15: initAdvertiseData

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


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