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 |
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 sendPayLoad(final String endPointId) { | |
Payload bytesPayload = Payload.fromBytes(String.valueOf(timestamp).getBytes()); | |
Nearby.getConnectionsClient(BaseApplication.getInstance() | |
.getActivity()).sendPayload(endPointId, bytesPayload).addOnSuccessListener(new OnSuccessListener<Void>() { | |
@Override | |
public void onSuccess(Void aVoid) { | |
} | |
}).addOnFailureListener(new OnFailureListener() { | |
@Override | |
public void onFailure(@NonNull Exception e) { |
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 startDiscovery() { | |
DiscoveryOptions discoveryOptions = new DiscoveryOptions.Builder().setStrategy(STRATEGY).build(); | |
Nearby.getConnectionsClient(BaseApplication.getInstance() | |
.getActivity()). | |
startDiscovery(SERVICE_ID, new EndpointDiscoveryCallback() { | |
@Override | |
public void onEndpointFound(@NonNull String endpointId, @NonNull DiscoveredEndpointInfo discoveredEndpointInfo) { | |
Nearby.getConnectionsClient(BaseApplication.getInstance() | |
.getActivity()). | |
requestConnection("Device B", endpointId, new ConnectionLifecycleCallback() { |
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 final PayloadCallback mPayloadCallback = new PayloadCallback() { | |
@Override | |
public void onPayloadReceived(@NonNull String s, @NonNull Payload payload) { | |
final byte[] receivedBytes = payload.asBytes(); | |
AppUtil.runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
long timestamp = System.currentTimeMillis(); | |
long timeTaken=(timestamp-Long.valueOf(new String(receivedBytes)))/1000; | |
strReceived=strReceived+"\n"+timeTaken +""+" sec"+"\n"; |
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
compile ‘com.google.android.gms:play-services-nearby:15.0.0’ |
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
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/rootView" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:background="@color/background_color"> | |
<WebView | |
android:id="@+id/web_view" | |
android:layout_width="match_parent" |
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
rootView.setFitsSystemWindows(true); | |
rootView.setPadding(rootView.getPaddingLeft(), -BaseApplication.getStatusBarHeight(), rootView.getPaddingRight(), rootView.getPaddingBottom()); | |
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
public static int getStatusBarHeight() { | |
int statusBarHeight = 0; | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
int resourceId = getContext().getResources() | |
.getIdentifier("status_bar_height", "dimen", "android"); | |
if (resourceId > 0) { | |
statusBarHeight = getContext().getResources() | |
.getDimensionPixelSize(resourceId); | |
} | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/rootView" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:fitsSystemWindows="true" | |
android:orientation="vertical"> | |
<WebView | |
android:id="@+id/manager_web_view" |
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
val locationPermissionRequest = registerForActivityResult( | |
ActivityResultContracts.RequestMultiplePermissions()) { permissions -> | |
when { | |
permissions.getOrDefault(Manifest.permission.ACCESS_FINE_LOCATION, false) -> { | |
// Precise location access granted. | |
} | |
permissions.getOrDefault(Manifest.permission.ACCESS_COARSE_LOCATION, false) -> { | |
// Only approximate location access granted. | |
} | |
else -> { |
OlderNewer