com.google.android.gms.nearby.messages.Strategy Java Examples

The following examples show how to use com.google.android.gms.nearby.messages.Strategy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From nearby-beacons with MIT License 6 votes vote down vote up
private void subscribe() {
    Log.d(TAG, "Subscribing…");
    SubscribeOptions options = new SubscribeOptions.Builder()
            .setStrategy(Strategy.BLE_ONLY)
            .build();
    //Active subscription for foreground messages
    Nearby.Messages.subscribe(mGoogleApiClient,
            mMessageListener, options);

    //Passive subscription for background messages
    Intent serviceIntent = new Intent(this, BeaconService.class);
    PendingIntent trigger = PendingIntent.getService(this, 0,
            serviceIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    ResultCallback<Status> callback = new BackgroundRegisterCallback();
    Nearby.Messages.subscribe(mGoogleApiClient, trigger, options)
            .setResultCallback(callback);

}
 
Example #2
Source File: MainActivity.java    From connectivity-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Calls {@link Messages#subscribe(GoogleApiClient, MessageListener, SubscribeOptions)},
 * using a {@link Strategy} for BLE scanning. Attaches a {@link ResultCallback} to monitor
 * whether the call to {@code subscribe()} succeeded or failed.
 */
private void subscribe() {
    // In this sample, we subscribe when the activity is launched, but not on device orientation
    // change.
    if (mSubscribed) {
        Log.i(TAG, "Already subscribed.");
        return;
    }

    SubscribeOptions options = new SubscribeOptions.Builder()
            .setStrategy(Strategy.BLE_ONLY)
            .build();

    Nearby.Messages.subscribe(mGoogleApiClient, getPendingIntent(), options)
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if (status.isSuccess()) {
                        Log.i(TAG, "Subscribed successfully.");
                        startService(getBackgroundSubscribeServiceIntent());
                    } else {
                        Log.e(TAG, "Operation failed. Error: " +
                                NearbyMessagesStatusCodes.getStatusCodeString(
                                        status.getStatusCode()));
                    }
                }
            });
}
 
Example #3
Source File: MainActivity.java    From hello-beacons with Apache License 2.0 5 votes vote down vote up
/**
 * Calls {@link Messages#subscribe(GoogleApiClient, MessageListener, SubscribeOptions)},
 * using a {@link Strategy} for BLE scanning. Attaches a {@link ResultCallback} to monitor
 * whether the call to {@code subscribe()} succeeded or failed.
 */
private void subscribe() {
    // In this sample, we subscribe when the activity is launched, but not on device orientation
    // change.
    if (mSubscribed) {
        Log.i(TAG, "Already subscribed.");
        return;
    }

    SubscribeOptions options = new SubscribeOptions.Builder()
            .setStrategy(Strategy.BLE_ONLY)
            .build();

    Nearby.Messages.subscribe(mGoogleApiClient, getPendingIntent(), options)
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if (status.isSuccess()) {
                        Log.i(TAG, "Subscribed successfully.");
                        startService(getBackgroundSubscribeServiceIntent());
                    } else {
                        Log.e(TAG, "Operation failed. Error: " +
                                NearbyMessagesStatusCodes.getStatusCodeString(
                                        status.getStatusCode()));
                    }
                }
            });
}
 
Example #4
Source File: MainActivity.java    From hello-beacons with Apache License 2.0 5 votes vote down vote up
/**
 * Calls {@link Messages#subscribe(GoogleApiClient, MessageListener, SubscribeOptions)},
 * using a {@link Strategy} for BLE scanning. Attaches a {@link ResultCallback} to monitor
 * whether the call to {@code subscribe()} succeeded or failed.
 */
private void subscribe() {
    // In this sample, we subscribe when the activity is launched, but not on device orientation
    // change.
    if (mSubscribed) {
        Log.i(TAG, "Already subscribed.");
        return;
    }

    SubscribeOptions options = new SubscribeOptions.Builder()
            .setStrategy(Strategy.BLE_ONLY)
            .build();

    Nearby.Messages.subscribe(mGoogleApiClient, getPendingIntent(), options)
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if (status.isSuccess()) {
                        Log.i(TAG, "Subscribed successfully.");
                        startService(getBackgroundSubscribeServiceIntent());
                    } else {
                        Log.e(TAG, "Operation failed. Error: " +
                                NearbyMessagesStatusCodes.getStatusCodeString(
                                        status.getStatusCode()));
                    }
                }
            });
}
 
Example #5
Source File: NearbySubscription.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
protected static SubscribeOptions createSubscribeOptions() {
    MessageFilter messageFilter = PhysicalWebBleClient.getInstance().modifyMessageFilterBuilder(
            new MessageFilter.Builder())
            .build();
    return new SubscribeOptions.Builder()
            .setStrategy(Strategy.BLE_ONLY)
            .setFilter(messageFilter)
            .build();
}
 
Example #6
Source File: NearbySubscription.java    From 365browser with Apache License 2.0 5 votes vote down vote up
protected static SubscribeOptions createSubscribeOptions() {
    MessageFilter messageFilter = PhysicalWebBleClient.getInstance().modifyMessageFilterBuilder(
            new MessageFilter.Builder())
            .build();
    return new SubscribeOptions.Builder()
            .setStrategy(Strategy.BLE_ONLY)
            .setFilter(messageFilter)
            .build();
}