mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-06-05 21:49:21 +02:00
delete invalid packages from our database
This commit is contained in:
parent
e13efcaab8
commit
d7219a5d0f
@ -2,6 +2,7 @@ package com.simplemobiletools.applauncher.helpers
|
|||||||
|
|
||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.database.sqlite.SQLiteDatabase
|
import android.database.sqlite.SQLiteDatabase
|
||||||
import android.database.sqlite.SQLiteOpenHelper
|
import android.database.sqlite.SQLiteOpenHelper
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
@ -107,6 +108,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
val launchers = ArrayList<AppLauncher>()
|
val launchers = ArrayList<AppLauncher>()
|
||||||
val cols = arrayOf(COL_ID, COL_NAME, COL_PKG_NAME)
|
val cols = arrayOf(COL_ID, COL_NAME, COL_PKG_NAME)
|
||||||
val cursor = mDb.query(MAIN_TABLE_NAME, cols, null, null, null, null, "$COL_NAME COLLATE NOCASE")
|
val cursor = mDb.query(MAIN_TABLE_NAME, cols, null, null, null, null, "$COL_NAME COLLATE NOCASE")
|
||||||
|
val IDsToDelete = ArrayList<String>()
|
||||||
cursor.use {
|
cursor.use {
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
val id = cursor.getIntValue(COL_ID)
|
val id = cursor.getIntValue(COL_ID)
|
||||||
@ -116,13 +118,22 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
val drawable = if (packageName.isAPredefinedApp()) {
|
val drawable = if (packageName.isAPredefinedApp()) {
|
||||||
resources.getLauncherDrawable(packageName)
|
resources.getLauncherDrawable(packageName)
|
||||||
} else {
|
} else {
|
||||||
packageManager.getApplicationIcon(packageName)
|
try {
|
||||||
|
packageManager.getApplicationIcon(packageName)
|
||||||
|
} catch (e: PackageManager.NameNotFoundException) {
|
||||||
|
IDsToDelete.add(id.toString())
|
||||||
|
}
|
||||||
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
val launcher = AppLauncher(id, name, packageName, drawable)
|
if (drawable != null) {
|
||||||
launchers.add(launcher)
|
val launcher = AppLauncher(id, name, packageName, drawable)
|
||||||
|
launchers.add(launcher)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteLaunchers(IDsToDelete)
|
||||||
return launchers
|
return launchers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user