Class DynamicPackageUtils
java.lang.Object
com.pranavpandey.android.dynamic.util.DynamicPackageUtils
Helper class to get package or app related information.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Drawable
getActivityIcon
(Context context, ComponentName componentName) Load activity icon from the given component name.static int
getActivityIconRes
(Context context, ComponentName componentName) Load activity icon resource from the given component name.static Drawable
getAppIcon
(Context context) Load application icon from the given context.static Drawable
getAppIcon
(Context context, String packageName) Load application icon from the given package.static CharSequence
getAppLabel
(Context context) Get application label from the given context.static CharSequence
getAppLabel
(Context context, String packageName) Get application label from the given package.static ComponentName
getComponentName
(Context context) Get component name from the given context.static String
getVersionCode
(Context context) Get package version code from the given context.static String
getVersionCode
(Context context, String packageName) Get package version code from the given package.static String
getVersionName
(Context context) Get package version name from the given context.static String
getVersionName
(Context context, String packageName) Get package version name from the given package.static boolean
isPackageExists
(Context context, String packageName) Checks if a given package name exits.static boolean
isSystemApp
(ApplicationInfo applicationInfo) Detects if the given application info is a system app or not.
-
Field Details
-
ID_NULL
Thenull
resource 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@null
in XML.- See Also:
-
-
Constructor Details
-
DynamicPackageUtils
public DynamicPackageUtils()
-
-
Method Details
-
isPackageExists
Checks if a given package name exits.- Parameters:
context
- The context to get the package manager.packageName
- The package name to be checked.- Returns:
true
if the given package name exits.
-
getComponentName
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:
-
getAppLabel
@Nullable public static CharSequence getAppLabel(@Nullable Context context, @Nullable 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:
-
getAppLabel
Get application label from the given context.- Parameters:
context
- The context to get the package manager.- Returns:
- The application label or name.
- See Also:
-
getVersionCode
@Nullable public static String getVersionCode(@Nullable Context context, @Nullable 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:
-
getVersionCode
Get package version code from the given context.- Parameters:
context
- The context to get the package manager.- Returns:
- The package version code.
- See Also:
-
getVersionName
@Nullable public static String getVersionName(@Nullable Context context, @Nullable 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:
-
getVersionName
Get package version name from the given context.- Parameters:
context
- The context to get the package manager.- Returns:
- The package version name.
- See Also:
-
getAppIcon
@Nullable public static Drawable getAppIcon(@Nullable Context context, @Nullable 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:
-
getAppIcon
Load application icon from the given context.- Parameters:
context
- The context to get the package manager.- Returns:
- The application icon drawable.
- See Also:
-
getActivityIcon
@Nullable public static Drawable getActivityIcon(@Nullable Context context, @Nullable 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:
-
getActivityIconRes
@DrawableRes public static int getActivityIconRes(@Nullable Context context, @Nullable 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:
-
isSystemApp
Detects if the given application info is a system app or not.- Parameters:
applicationInfo
- The application info of the package.- Returns:
true
if the associated package is a system app.
-