Class DynamicPackageUtils
java.lang.Object
com.pranavpandey.android.dynamic.util.DynamicPackageUtils
Helper class to get package or app related information.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DrawablegetActivityIcon(Context context, ComponentName componentName) Load activity icon from the given component name.static intgetActivityIconRes(Context context, ComponentName componentName) Load activity icon resource from the given component name.static DrawablegetAppIcon(Context context) Load application icon from the given context.static DrawablegetAppIcon(Context context, String packageName) Load application icon from the given package.static CharSequencegetAppLabel(Context context) Get application label from the given context.static CharSequencegetAppLabel(Context context, String packageName) Get application label from the given package.static ComponentNamegetComponentName(Context context) Get component name from the given context.static StringgetVersionCode(Context context) Get package version code from the given context.static StringgetVersionCode(Context context, String packageName) Get package version code from the given package.static StringgetVersionName(Context context) Get package version name from the given context.static StringgetVersionName(Context context, String packageName) Get package version name from the given package.static booleanisPackageExists(Context context, String packageName) Checks if a given package name exits.static booleanisSystemApp(ApplicationInfo applicationInfo) Detects if the given application info is a system app or not.
-
Field Details
-
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:
-
-
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:
trueif 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:
trueif the associated package is a system app.
-