feat: redesign and lots of progress
This commit is contained in:
@ -1,5 +1,55 @@
|
||||
package com.example.abawo_bt_app
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import io.reactivex.exceptions.UndeliverableException
|
||||
import io.reactivex.plugins.RxJavaPlugins
|
||||
|
||||
class MainActivity: FlutterActivity()
|
||||
class MainActivity: FlutterActivity() {
|
||||
private val settingsChannel = "abawo/settings"
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
RxJavaPlugins.setErrorHandler { throwable ->
|
||||
val error = if (throwable is UndeliverableException && throwable.cause != null) {
|
||||
throwable.cause!!
|
||||
} else {
|
||||
throwable
|
||||
}
|
||||
val className = error.javaClass.name
|
||||
val message = error.message.orEmpty()
|
||||
if (className.contains("BleGatt") || message.contains("GATT exception")) {
|
||||
return@setErrorHandler
|
||||
}
|
||||
Thread.currentThread().uncaughtExceptionHandler
|
||||
?.uncaughtException(Thread.currentThread(), error)
|
||||
}
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, settingsChannel)
|
||||
.setMethodCallHandler { call, result ->
|
||||
when (call.method) {
|
||||
"openBluetoothSettings" -> {
|
||||
try {
|
||||
startActivity(Intent(Settings.ACTION_BLUETOOTH_SETTINGS))
|
||||
result.success(true)
|
||||
} catch (_: Exception) {
|
||||
try {
|
||||
startActivity(Intent(Settings.ACTION_SETTINGS))
|
||||
result.success(true)
|
||||
} catch (_: Exception) {
|
||||
result.success(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user