Last active
November 9, 2019 18:12
-
-
Save Suchiq/6c174c6563b5315f8a72de21e0a96905 to your computer and use it in GitHub Desktop.
code for Device A (Advertiser)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void startAdvertising () { | |
AdvertisingOptions advertisingOptions = new AdvertisingOptions.Builder().setStrategy(STRATEGY).build(); | |
Nearby.getConnectionsClient(BaseApplication.getInstance() | |
.getActivity()).startAdvertising("Device A", SERVICE_ID, new ConnectionLifecycleCallback() { | |
@Override | |
public void onConnectionInitiated(@NonNull String endPointId, @NonNull ConnectionInfo connectionInfo) { | |
Nearby.getConnectionsClient(BaseApplication.getInstance() | |
.getActivity().acceptConnection(endPointId, mPayloadCallback); | |
} | |
@Override | |
public void onConnectionResult(@NonNull String endPointId, @NonNull ConnectionResolution connectionResolution) { | |
switch (connectionResolution.getStatus().getStatusCode()) { | |
case ConnectionsStatusCodes.STATUS_OK: | |
// We're connected! Can now start sending and receiving data. | |
strendPointId = endPointId; | |
sendPayLoad(strendPointId); | |
break; | |
case ConnectionsStatusCodes.STATUS_CONNECTION_REJECTED: | |
// The connection was rejected by one or both sides. | |
break; | |
case ConnectionsStatusCodes.STATUS_ERROR: | |
// The connection broke before it was able to be accepted. | |
break; | |
default: | |
// Unknown status code | |
} | |
} | |
@Override | |
public void onDisconnected(@NonNull String s) { | |
strendPointId = null; | |
} | |
}, advertisingOptions); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment