Merge pull request #95 from esensar/feature/disable-uninstall-of-system-apps
Hide uninstall button for system apps
This commit is contained in:
commit
d331d70131
|
@ -584,7 +584,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
|||
menu.findItem(R.id.hide_icon).isVisible = gridItem.type == ITEM_TYPE_ICON && isOnAllAppsFragment
|
||||
menu.findItem(R.id.resize).isVisible = gridItem.type == ITEM_TYPE_WIDGET
|
||||
menu.findItem(R.id.app_info).isVisible = gridItem.type == ITEM_TYPE_ICON
|
||||
menu.findItem(R.id.uninstall).isVisible = gridItem.type == ITEM_TYPE_ICON
|
||||
menu.findItem(R.id.uninstall).isVisible = gridItem.type == ITEM_TYPE_ICON && isUninstallable(gridItem.packageName)
|
||||
menu.findItem(R.id.remove).isVisible = !isOnAllAppsFragment
|
||||
setOnMenuItemClickListener { item ->
|
||||
resetFragmentTouches()
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.simplemobiletools.launcher.extensions
|
|||
import android.app.Activity
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.net.Uri
|
||||
import android.provider.Settings
|
||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
|
@ -41,6 +42,14 @@ fun Activity.launchAppInfo(packageName: String) {
|
|||
}
|
||||
}
|
||||
|
||||
fun Activity.isUninstallable(packageName: String): Boolean {
|
||||
return try {
|
||||
(packageManager.getApplicationInfo(packageName, 0).flags and ApplicationInfo.FLAG_SYSTEM) == 0
|
||||
} catch (ignored: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fun Activity.uninstallApp(packageName: String) {
|
||||
Intent(Intent.ACTION_DELETE).apply {
|
||||
data = Uri.fromParts("package", packageName, null)
|
||||
|
|
Loading…
Reference in New Issue