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
package com.germanautolabs.chris.utils | |
import android.content.Context | |
import android.graphics.Canvas | |
import android.graphics.Rect | |
import android.graphics.drawable.Drawable | |
import android.support.v7.widget.LinearLayoutManager | |
import android.support.v7.widget.RecyclerView | |
import android.util.Log | |
import android.view.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 scanFilters = listOf( | |
ScanFilter.Builder() | |
.setManufacturerData(manufacturerId, manufacturerData, manufacturerDataMask) | |
.build() | |
) | |
bluetoothScanner.startScan( | |
scanFilters, | |
settings, | |
scanCallback |
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 scanResponse = AdvertiseData.Builder() | |
.addServiceUuid(userUuid.toParcelUuid()) | |
.build() | |
bluetoothAdvertiser.startAdvertising( | |
advertiseSettings, | |
advertiseData, | |
scanResponse, | |
advertiseCallback | |
) |
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
if (!closeToMe.hasBleFeature()) { | |
Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_LONG).show() | |
finish() | |
} |
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
closeToMe.start(object : CloseToMeCallback { | |
override fun onSuccess() { | |
log("Beacon started successfully!") | |
} | |
override fun onError(throwable: Throwable) { | |
log(throwable.message) | |
} | |
}) |
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
closeToMe.results.observe(this, Observer { results -> | |
log("Result: results) | |
}) |
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
closeToMe.isBluetoothEnabled.observe(this, Observer { isActive-> | |
log("Bluetooth isActive: $isActive") | |
if (isActive == false) { | |
// start again | |
} else { | |
// do something | |
} | |
}) |
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
closeToMe.state.observe(this, Observer { state -> | |
log("Beacon state: $state") | |
when (state) { | |
CloseToMeState.STARTED -> { | |
// do something | |
} | |
else -> { | |
// do other thing | |
} |
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
<uses-permission android:name="android.permission.BLUETOOTH" /> | |
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> | |
<!-- Privacy changes in Android 10 requires ACCESS_FINE_LOCATION | |
https://developer.android.com/about/versions/10/privacy/changes --> | |
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> |
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
closeToMe = CloseToMe.Builder(context, manufacturerUuid) | |
.setUserUuid(userUuid) | |
.setMajor(1U) | |
.setMinor(1U) | |
.setVisibilityDistanceMeter(3.0) | |
.setVisibilityTimeoutMs(5_000) | |
.build() |
NewerOlder