Class DynamicPackageUtils
- java.lang.Object
-
- com.pranavpandey.android.dynamic.util.DynamicPackageUtils
-
public class DynamicPackageUtils extends java.lang.ObjectHelper class to get package or app related information.
-
-
Field Summary
Fields Modifier and Type Field Description static intID_NULLThenullresource ID.
-
Constructor Summary
Constructors Constructor Description DynamicPackageUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static android.graphics.drawable.DrawablegetActivityIcon(android.content.Context context, android.content.ComponentName componentName)Load activity icon from the given component name.static intgetActivityIconRes(android.content.Context context, android.content.ComponentName componentName)Load activity icon resource from the given component name.static android.graphics.drawable.DrawablegetAppIcon(android.content.Context context)Load application icon from the given context.static android.graphics.drawable.DrawablegetAppIcon(android.content.Context context, java.lang.String packageName)Load application icon from the given package.static java.lang.CharSequencegetAppLabel(android.content.Context context)Get application label from the given context.static java.lang.CharSequencegetAppLabel(android.content.Context context, java.lang.String packageName)Get application label from the given package.static android.content.ComponentNamegetComponentName(android.content.Context context)Get component name from the given context.static java.lang.StringgetVersionCode(android.content.Context context)Get package version code from the given context.static java.lang.StringgetVersionCode(android.content.Context context, java.lang.String packageName)Get package version code from the given package.static java.lang.StringgetVersionName(android.content.Context context)Get package version name from the given context.static java.lang.StringgetVersionName(android.content.Context context, java.lang.String packageName)Get package version name from the given package.static booleanisPackageExists(android.content.Context context, java.lang.String packageName)Checks if a given package name exits.static booleanisSystemApp(android.content.pm.ApplicationInfo applicationInfo)Detects if the given application info is a system app or not.
-
-
-
Field Detail
-
ID_NULL
@AnyRes public static final int ID_NULL
Thenullresource ID. This denotes an invalid resource ID that is returned by the system when a resource is not found or the value is set to@nullin XML.- See Also:
- Constant Field Values
-
-
Method Detail
-
isPackageExists
public static boolean isPackageExists(@Nullable android.content.Context context, @Nullable java.lang.String packageName)Checks if a given package name exits.- Parameters:
context- The context to get the package manager.packageName- The package name to be checked.- Returns:
trueif the given package name exits.
-
getComponentName
@NonNull public static android.content.ComponentName getComponentName(@NonNull android.content.Context context)Get component name from the given context.- Parameters:
context- The context to build the component.- Returns:
- The component name from the given context.
- See Also:
ComponentName(String, String)
-
getAppLabel
@Nullable public static java.lang.CharSequence getAppLabel(@Nullable android.content.Context context, @Nullable java.lang.String packageName)Get application label from the given package.- Parameters:
context- The context to get the package manager.packageName- The package name of the app to get its label.- Returns:
- The application label or name.
- See Also:
PackageItemInfo.loadLabel(PackageManager)
-
getAppLabel
@Nullable public static java.lang.CharSequence getAppLabel(@Nullable android.content.Context context)Get application label from the given context.- Parameters:
context- The context to get the package manager.- Returns:
- The application label or name.
- See Also:
PackageItemInfo.loadLabel(PackageManager)
-
getVersionCode
@Nullable public static java.lang.String getVersionCode(@Nullable android.content.Context context, @Nullable java.lang.String packageName)Get package version code from the given package.- Parameters:
context- The context to get the package manager.packageName- The package name to get its version code.- Returns:
- The package version code.
- See Also:
PackageInfo.versionCode
-
getVersionCode
@Nullable public static java.lang.String getVersionCode(@Nullable android.content.Context context)Get package version code from the given context.- Parameters:
context- The context to get the package manager.- Returns:
- The package version code.
- See Also:
PackageInfo.versionCode
-
getVersionName
@Nullable public static java.lang.String getVersionName(@Nullable android.content.Context context, @Nullable java.lang.String packageName)Get package version name from the given package.- Parameters:
context- The context to get the package manager.packageName- The package name to get its version name.- Returns:
- The package version name.
- See Also:
PackageInfo.versionName
-
getVersionName
@Nullable public static java.lang.String getVersionName(@Nullable android.content.Context context)Get package version name from the given context.- Parameters:
context- The context to get the package manager.- Returns:
- The package version name.
- See Also:
PackageInfo.versionName
-
getAppIcon
@Nullable public static android.graphics.drawable.Drawable getAppIcon(@Nullable android.content.Context context, @Nullable java.lang.String packageName)Load application icon from the given package.- Parameters:
context- The context to get the package manager.packageName- The package name of the app to load its icon.- Returns:
- The application icon drawable.
- See Also:
PackageItemInfo.loadIcon(PackageManager)
-
getAppIcon
@Nullable public static android.graphics.drawable.Drawable getAppIcon(@Nullable android.content.Context context)Load application icon from the given context.- Parameters:
context- The context to get the package manager.- Returns:
- The application icon drawable.
- See Also:
PackageItemInfo.loadIcon(PackageManager)
-
getActivityIcon
@Nullable public static android.graphics.drawable.Drawable getActivityIcon(@Nullable android.content.Context context, @Nullable android.content.ComponentName componentName)Load activity icon from the given component name.- Parameters:
context- The context to get the package manager.componentName- The component name to be used.- Returns:
- The activity icon drawable.
- See Also:
PackageManager.getActivityIcon(ComponentName),PackageManager.getDefaultActivityIcon()
-
getActivityIconRes
@DrawableRes public static int getActivityIconRes(@Nullable android.content.Context context, @Nullable android.content.ComponentName componentName)Load activity icon resource from the given component name.- Parameters:
context- The context to get the package manager.componentName- The component name to be used.- Returns:
- The activity icon resource.
- See Also:
PackageManager.getActivityIcon(ComponentName),PackageManager.getDefaultActivityIcon()
-
isSystemApp
public static boolean isSystemApp(@Nullable android.content.pm.ApplicationInfo applicationInfo)Detects if the given application info is a system app or not.- Parameters:
applicationInfo- The application info of the package.- Returns:
trueif the associated package is a system app.
-
-