2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 13:47:41 +00:00

refactor: migrate AppsHelper to Kotlin

Remove `appIconLookup()` as not used
This commit is contained in:
ShellWen Chen
2024-04-06 06:25:19 +08:00
committed by Albert Vaca Cintora
parent c2e1a93f68
commit 5ce0c1ccf8
2 changed files with 25 additions and 49 deletions

View File

@@ -1,49 +0,0 @@
/*
* SPDX-FileCopyrightText: 2014 Albert Vaca Cintora <albertvaka@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
package org.kde.kdeconnect.Helpers;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.util.Log;
public class AppsHelper {
public static String appNameLookup(Context context, String packageName) {
try {
PackageManager pm = context.getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
return pm.getApplicationLabel(ai).toString();
} catch (final PackageManager.NameNotFoundException e) {
Log.e("AppsHelper", "Could not resolve name " + packageName, e);
return null;
}
}
public static Drawable appIconLookup(Context context, String packageName) {
try {
PackageManager pm = context.getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
return pm.getApplicationIcon(ai);
} catch (final PackageManager.NameNotFoundException e) {
Log.e("AppsHelper", "Could not find icon for " + packageName, e);
return null;
}
}
}

View File

@@ -0,0 +1,25 @@
/*
* SPDX-FileCopyrightText: 2014 Albert Vaca Cintora <albertvaka@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
package org.kde.kdeconnect.Helpers
import android.content.Context
import android.content.pm.PackageManager
import android.util.Log
object AppsHelper {
@JvmStatic
fun appNameLookup(context: Context, packageName: String): String? {
return try {
val manager = context.packageManager
val info = manager.getApplicationInfo(packageName, 0)
manager.getApplicationLabel(info).toString()
} catch (e: PackageManager.NameNotFoundException) {
Log.e("AppsHelper", "Could not resolve name $packageName", e)
null
}
}
}