mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 05:37:43 +00:00
refactor: migrate AppsHelper
to Kotlin
Remove `appIconLookup()` as not used
This commit is contained in:
parent
c2e1a93f68
commit
5ce0c1ccf8
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
25
src/org/kde/kdeconnect/Helpers/AppsHelper.kt
Normal file
25
src/org/kde/kdeconnect/Helpers/AppsHelper.kt
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user