Skip to content

Instantly share code, notes, and snippets.

View mohsenoid's full-sized avatar
:octocat:
What can go wrong?!

Mohsen Mirhoseini mohsenoid

:octocat:
What can go wrong?!
View GitHub Profile
@mohsenoid
mohsenoid / ClosetToMeStartScanning.kt
Last active April 26, 2020 10:28
ClosetToMe - Start Scanning
val scanFilters = listOf(
ScanFilter.Builder()
.setManufacturerData(manufacturerId, manufacturerData, manufacturerDataMask)
.build()
)
bluetoothScanner.startScan(
scanFilters,
settings,
scanCallback
@mohsenoid
mohsenoid / CloseToMeStartAdvertising.kt
Last active April 26, 2020 10:26
CloseToMe - Start Advertising
val scanResponse = AdvertiseData.Builder()
.addServiceUuid(userUuid.toParcelUuid())
.build()
bluetoothAdvertiser.startAdvertising(
advertiseSettings,
advertiseData,
scanResponse,
advertiseCallback
)
@mohsenoid
mohsenoid / CloseToMeHasBleFeature.kt
Created April 26, 2020 09:30
CloseToMe - Check if device has BLE Feature
if (!closeToMe.hasBleFeature()) {
Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_LONG).show()
finish()
}
@mohsenoid
mohsenoid / CloseToMeStart.kt
Created April 26, 2020 09:28
CloseToMe - Start
closeToMe.start(object : CloseToMeCallback {
override fun onSuccess() {
log("Beacon started successfully!")
}
override fun onError(throwable: Throwable) {
log(throwable.message)
}
})
@mohsenoid
mohsenoid / CloseToMeResults.kt
Created April 26, 2020 09:20
CloseToMe - Observing Scan Results
closeToMe.results.observe(this, Observer { results ->
log("Result: results)
})
@mohsenoid
mohsenoid / CloseToMeBluetoothState.kt
Created April 26, 2020 09:19
CloseToMe - Observing Bluetooth State
closeToMe.isBluetoothEnabled.observe(this, Observer { isActive->
log("Bluetooth isActive: $isActive")
if (isActive == false) {
// start again
} else {
// do something
}
})
@mohsenoid
mohsenoid / CloseToMeState.kt
Created April 26, 2020 09:18
CloseToMe - Observing State
closeToMe.state.observe(this, Observer { state ->
log("Beacon state: $state")
when (state) {
CloseToMeState.STARTED -> {
// do something
}
else -> {
// do other thing
}
@mohsenoid
mohsenoid / CloseToMePermissions.xml
Last active April 26, 2020 09:16
CloseToMe - Android Permissions
<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" />
@mohsenoid
mohsenoid / CloseToMeBuilder.kt
Last active April 26, 2020 09:13
CloseToMe - Builder
closeToMe = CloseToMe.Builder(context, manufacturerUuid)
.setUserUuid(userUuid)
.setMajor(1U)
.setMinor(1U)
.setVisibilityDistanceMeter(3.0)
.setVisibilityTimeoutMs(5_000)
.build()

Keybase proof

I hereby claim:

  • I am mohsenoid on github.
  • I am mohsenoid (https://keybase.io/mohsenoid) on keybase.
  • I have a public key ASCmbE-Oa-53fhh-NupPHcgx4L8kF5uq83h7yqc7Hi9-4Ao

To claim this, I am signing this object: