|
@@ -4,6 +4,7 @@ import android.Manifest
|
|
|
import android.app.Activity
|
|
import android.app.Activity
|
|
|
import android.bluetooth.BluetoothAdapter
|
|
import android.bluetooth.BluetoothAdapter
|
|
|
import android.bluetooth.BluetoothManager
|
|
import android.bluetooth.BluetoothManager
|
|
|
|
|
+import android.content.Intent
|
|
|
import android.content.pm.PackageManager
|
|
import android.content.pm.PackageManager
|
|
|
import android.location.Geocoder
|
|
import android.location.Geocoder
|
|
|
import android.location.Location
|
|
import android.location.Location
|
|
@@ -13,6 +14,7 @@ import android.os.Build
|
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
|
import android.os.Handler
|
|
import android.os.Handler
|
|
|
import android.os.Looper
|
|
import android.os.Looper
|
|
|
|
|
+import android.provider.Settings
|
|
|
import io.flutter.plugin.common.BinaryMessenger
|
|
import io.flutter.plugin.common.BinaryMessenger
|
|
|
import io.flutter.plugin.common.MethodCall
|
|
import io.flutter.plugin.common.MethodCall
|
|
|
import io.flutter.plugin.common.MethodChannel
|
|
import io.flutter.plugin.common.MethodChannel
|
|
@@ -68,6 +70,7 @@ class TelemetryBridge(private val activity: Activity) : MethodChannel.MethodCall
|
|
|
when (call.method) {
|
|
when (call.method) {
|
|
|
"listBondedDevices" -> listBondedDevices(result)
|
|
"listBondedDevices" -> listBondedDevices(result)
|
|
|
"isBluetoothEnabled" -> result.success(bluetoothAdapter()?.isEnabled == true)
|
|
"isBluetoothEnabled" -> result.success(bluetoothAdapter()?.isEnabled == true)
|
|
|
|
|
+ "openBluetoothSettings" -> result.success(openBluetoothSettings())
|
|
|
"ensureBluetoothPermission" -> ensurePermission(KIND_BLUETOOTH, result)
|
|
"ensureBluetoothPermission" -> ensurePermission(KIND_BLUETOOTH, result)
|
|
|
"ensureLocationPermission" -> ensurePermission(KIND_LOCATION, result)
|
|
"ensureLocationPermission" -> ensurePermission(KIND_LOCATION, result)
|
|
|
"getLocation" -> getLocation(result)
|
|
"getLocation" -> getLocation(result)
|
|
@@ -120,6 +123,17 @@ class TelemetryBridge(private val activity: Activity) : MethodChannel.MethodCall
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private fun openBluetoothSettings(): Boolean {
|
|
|
|
|
+ return try {
|
|
|
|
|
+ val intent = Intent(Settings.ACTION_BLUETOOTH_SETTINGS)
|
|
|
|
|
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
|
|
+ activity.startActivity(intent)
|
|
|
|
|
+ true
|
|
|
|
|
+ } catch (_: Throwable) {
|
|
|
|
|
+ false
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private fun hasBluetoothPermission(): Boolean {
|
|
private fun hasBluetoothPermission(): Boolean {
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return true
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return true
|
|
|
return activity.checkSelfPermission(Manifest.permission.BLUETOOTH_CONNECT) ==
|
|
return activity.checkSelfPermission(Manifest.permission.BLUETOOTH_CONNECT) ==
|