diff --git a/build.gradle b/build.gradle index e7db1ba..bd71aba 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0-beta01' + classpath 'com.android.tools.build:gradle:4.0.0-beta03' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version" diff --git a/library/src/main/java/com/andruid/magic/eezetensions/Context.kt b/library/src/main/java/com/andruid/magic/eezetensions/Context.kt index 73d43f3..f327d97 100644 --- a/library/src/main/java/com/andruid/magic/eezetensions/Context.kt +++ b/library/src/main/java/com/andruid/magic/eezetensions/Context.kt @@ -70,8 +70,7 @@ fun Context.hasInternet(): Boolean { */ fun Context.getPackageVersion(): String? { return try { - val pInfo = packageManager.getPackageInfo(applicationContext.packageName, 0) - pInfo.versionName + packageManager.getPackageInfo(applicationContext.packageName, 0).versionName } catch (e: PackageManager.NameNotFoundException) { e.printStackTrace() null @@ -111,4 +110,25 @@ fun Context.toast(@StringRes msgRes: Int, duration: Int = Toast.LENGTH_SHORT, fr * @receiver context of the calling component */ fun Context.getUserDeviceName(): String = - Settings.Global.getString(contentResolver, "device_name") \ No newline at end of file + Settings.Global.getString(contentResolver, "device_name") + +/** + * Get the application name + * @return application name + * @receiver context of the calling component + */ +fun Context.getApplicationName(): String { + val stringId = applicationInfo.labelRes + return if (stringId == 0) + applicationInfo.nonLocalizedLabel.toString() + else + getString(stringId) +} + +/** + * Check whether mobile data is enabled + * @return true/false + * @receiver context of the calling component + */ +fun Context.isMobileDataEnabled() = + Settings.Global.getInt(contentResolver, "mobile_data", 1) == 1 \ No newline at end of file diff --git a/library/src/main/java/com/andruid/magic/eezetensions/Fragment.kt b/library/src/main/java/com/andruid/magic/eezetensions/Fragment.kt index 4ce6eca..ca57ac9 100644 --- a/library/src/main/java/com/andruid/magic/eezetensions/Fragment.kt +++ b/library/src/main/java/com/andruid/magic/eezetensions/Fragment.kt @@ -6,7 +6,6 @@ import android.content.Intent import android.widget.Toast import androidx.annotation.ColorRes import androidx.annotation.DrawableRes -import androidx.annotation.RequiresPermission import androidx.annotation.StringRes import androidx.fragment.app.Fragment diff --git a/library/src/main/java/com/andruid/magic/eezetensions/Intent.kt b/library/src/main/java/com/andruid/magic/eezetensions/Intent.kt index df411a7..8c81e21 100644 --- a/library/src/main/java/com/andruid/magic/eezetensions/Intent.kt +++ b/library/src/main/java/com/andruid/magic/eezetensions/Intent.kt @@ -16,4 +16,15 @@ fun Context.buildSettingsIntent(): Intent { val uri = Uri.fromParts("package", packageName, null) return Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) .setData(uri) +} + +/** + * Get intent to show hotspot settings screen + * @return intent to launch hotspot settings + * @receiver context of the calling component + */ +fun Context.buildHotspotSettingsIntent(): Intent { + return Intent() + .setClassName("com.android.settings", "com.android.settings.wifi.mobileap.WifiApSettings") + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) } \ No newline at end of file