From 9471cbe1fa32f5a4fc2d61c2dbcb7e37f3a267e7 Mon Sep 17 00:00:00 2001 From: lev Date: Thu, 28 Jan 2021 17:19:55 +0800 Subject: [PATCH] add hotspot setting --- .../system_settings/SystemSettingsPlugin.kt | 9 +++++++++ lib/system_settings.dart | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/android/src/main/kotlin/de/florianweinaug/system_settings/SystemSettingsPlugin.kt b/android/src/main/kotlin/de/florianweinaug/system_settings/SystemSettingsPlugin.kt index b134a55..2450c9a 100644 --- a/android/src/main/kotlin/de/florianweinaug/system_settings/SystemSettingsPlugin.kt +++ b/android/src/main/kotlin/de/florianweinaug/system_settings/SystemSettingsPlugin.kt @@ -24,6 +24,7 @@ public class SystemSettingsPlugin(private val registrar: Registrar): MethodCallH override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) { when (call.method) { "app" -> openAppSettings() + "hotspot" -> openHotsPot() "app-notifications" -> openAppNotificationSettings() "system" -> openSystemSettings() "location" -> openSetting(Settings.ACTION_LOCATION_SOURCE_SETTINGS) @@ -58,6 +59,14 @@ public class SystemSettingsPlugin(private val registrar: Registrar): MethodCallH registrar.context().startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) } + private fun openHotsPot(){ + try { + registrar.context().startActivity(Intent().apply{setClassName("com.android.settings", "com.android.settings.TetherSettings")}.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) + } catch (e: Exception) { + openSystemSettings() + } + } + private fun openAppNotificationSettings() { val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) diff --git a/lib/system_settings.dart b/lib/system_settings.dart index 4ceab90..1ad69b9 100644 --- a/lib/system_settings.dart +++ b/lib/system_settings.dart @@ -9,6 +9,10 @@ class SystemSettings { return await _channel.invokeMethod('app'); } + static Future hotsPot() async { + return await _channel.invokeMethod('hotspot'); + } + static Future appNotifications() async { return await _channel.invokeMethod('app-notifications'); }