Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix app crash for service not available to activity before onCreate #66

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions app/src/main/java/com/khmelenko/lab/mibanddemo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ import java.nio.ByteOrder
*/
class MainActivity : AppCompatActivity(), LocationListener {

private var miBand: MiBand = MiBand(this)
private val locationManager: LocationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
private val provider: String = LocationManager.GPS_PROVIDER
private lateinit var miBand: MiBand
private lateinit var locationManager: LocationManager
private lateinit var provider: String

private val disposables = CompositeDisposable()

public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
ButterKnife.bind(this)
miBand = MiBand(this)
provider = LocationManager.GPS_PROVIDER
locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager

checkLocationPermission()
}
Expand Down Expand Up @@ -111,7 +114,8 @@ class MainActivity : AppCompatActivity(), LocationListener {
fun actionSetHeartRateNotifyListener() {
miBand.setHeartRateScanListener(object : HeartRateNotifyListener {
override fun onNotify(heartRate: Int) {
Timber.d("heart rate: $heartRate") }
Timber.d("heart rate: $heartRate")
}
})
}

Expand Down Expand Up @@ -158,9 +162,10 @@ class MainActivity : AppCompatActivity(), LocationListener {

@OnClick(R.id.action_set_realtime_notify_listener)
fun actionSetRealtimeNotifyListener() {
miBand.setRealtimeStepsNotifyListener(object : RealtimeStepsNotifyListener{
miBand.setRealtimeStepsNotifyListener(object : RealtimeStepsNotifyListener {
override fun onNotify(steps: Int) {
Timber.d("RealtimeStepsNotifyListener:$steps") }
Timber.d("RealtimeStepsNotifyListener:$steps")
}
})
}

Expand All @@ -173,7 +178,8 @@ class MainActivity : AppCompatActivity(), LocationListener {
@OnClick(R.id.action_disable_realtime_steps_notify)
fun actionDisableRealtimeStepsNotify() {
val d = miBand.disableRealtimeStepsNotify().subscribe()
disposables.add(d) }
disposables.add(d)
}

@OnClick(R.id.action_set_sensor_data_notify_listener)
fun actionSetSensorDataNotifyListener() {
Expand Down