Switch to compat methods wherever possible
* Introduce custom compat methods with DEPRECATION suppressed if not present in public library Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -40,3 +40,13 @@ inline fun <reified T : Context> Context.newIntent(flags: Int, extras: Bundle):
|
||||
intent.putExtras(extras)
|
||||
return intent
|
||||
}
|
||||
|
||||
fun Intent.applyUninstallActionCompat() {
|
||||
if (isPAndAbove()) {
|
||||
action = Intent.ACTION_DELETE
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
action = Intent.ACTION_UNINSTALL_PACKAGE
|
||||
putExtra(Intent.EXTRA_RETURN_RESULT, true)
|
||||
}
|
||||
}
|
||||
|
||||
12
app/src/main/java/com/aurora/extensions/PackageManager.kt
Normal file
12
app/src/main/java/com/aurora/extensions/PackageManager.kt
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.aurora.extensions
|
||||
|
||||
import android.content.pm.PackageManager
|
||||
|
||||
fun PackageManager.getInstallerPackageNameCompat(packageName: String): String? {
|
||||
return if (isRAndAbove()) {
|
||||
getInstallSourceInfo(packageName).installingPackageName
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
return getInstallerPackageName(packageName)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user