public class

AppManager

extends Object
java.lang.Object
   ↳ com.datalogic.device.app.AppManager

Class Overview

AppManager gives developers the ability to manage installed applications.

Summary

Public Constructors
AppManager(Context context)
This is the constructor of AppManager.
Public Methods
int addBatteryOptimizationExemption(String packageName)
Call this method to place the given application package on the device's power allowlist.
int enableNotificationChannels(String packageName, String notificationChannels, boolean enabled)
Call this method to enable/disable the specified list of NotificationChannels of a given application.
int forceStopPackage(String packageName)
Call this method to stop an application.
int getNotificationChannels(String packageName, List<NotificationChannel> notificationChannels)
Call this method to get the list of NotificationChannel defined by a given application.
int grantAllPermissions(String packageName)
Call this method to grant an application all the permissions declared in its manifest.
int grantPermissions(String packageName, ArrayList<String> permissions)
Call this method to grant an application the specified permissions.
int removeBatteryOptimizationExemption(String packageName)
Call this method to remove the given application package from the device's power allowlist.
int revokePermissions(String packageName, ArrayList<String> permissions)
Call this method to revoke an application the specified permissions.
int setApplicationEnabledSetting(String packageName, int newState, int flags)
Call this method to set the enable setting for an application.
int setApplicationHidden(String packageName, boolean hidden)
Call this method to hide or unhide packages.
int setNotificationsEnabledForPackage(String packageName, boolean enabled)
Call this method to enable/disable the notifications of the given application.
int setStatusBarDisabled(boolean disabled)
Call this method to disable or enable the status bar.
int setUninstallBlocked(String packageName, boolean uninstallBlocked)
Change whether a user can uninstalling a package.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public AppManager (Context context)

Added in revision 25

This is the constructor of AppManager.

Parameters
context Context The context of the calling app.
Throws
AppManagerException in case of error, when exceptions are enabled through the ErrorManager singleton.

Public Methods

public int addBatteryOptimizationExemption (String packageName)

Added in revision 31

Call this method to place the given application package on the device's power allowlist.

Parameters
packageName String The name of the package to be added to the device's power allowlist.
Returns
Throws
AppManagerException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int enableNotificationChannels (String packageName, String notificationChannels, boolean enabled)

Added in revision 40

Call this method to enable/disable the specified list of NotificationChannels of a given application.
The NotificationChannels are specified using their identifier.
To enable/disable all the NotificationChannels of an app use as value of the parameter notificationChannels the regular expression "^(?:[\\w| ]*)$".
To disable all the NotificationChannels of the Clock app:

 AppManager appmanager = new AppManager(this);
 int result = appManager.enableNotificationChannels("com.google.android.deskclock", "^(?:[\\w| ]*)$", false);
 
To disable the NotificationChannels Bedtime, Timers, Firing alarms & timers, Missed alarms of the Clock app:
 AppManager appmanager = new AppManager(this);
 int result = appManager.enableNotificationChannels("com.google.android.deskclock", "^(?:Bedtime|Timers|Firing|Missed Alarms)$", false);
 
The identifier of the NotificationChannels are obtained getting the list of all the NotificationChannels of the app and looking, in the returned list, for their identifier.
 AppManager appmanager = new AppManager(this);
 List channels = new ArrayList();
 int result = appmanager.getNotificationChannels("com.google.android.deskclock", channels);
 for (NotificationChannel channel : channels) {
    Log.d(TAG, "channel=" + channel.getId());
 } 
 

Parameters
packageName String The package name of the application whose NotificationChannels are to be enabled/disabled.
notificationChannels String Regular expression that lists the identifiers of the NotificationChannels to be enabled/disabled.
enabled boolean False to disable the notification channels, true to enable the notification channels with the importance defined when the channel was created.
Returns
Throws
AppManagerException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int forceStopPackage (String packageName)

Added in revision 25

Call this method to stop an application.

Parameters
packageName String The package name of the application to be force stopped.
Returns
Throws
AppManagerException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int getNotificationChannels (String packageName, List<NotificationChannel> notificationChannels)

Added in revision 40

Call this method to get the list of NotificationChannel defined by a given application.
This method is usefull to know the NotificationChannel identifier to be used in enableNotificationChannels(String, String, boolean).
NotificationChannel name is the name, localized, used as label to show the NotificationChannel on the Android Settings..

Parameters
packageName String The package name of the application whose NotificationChannel is given back.
notificationChannels List<NotificationChannel>
Call the method passing an empty list. In output the list will contains the NotificationChannels defined by the given app.
Returns
Throws
AppManagerException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int grantAllPermissions (String packageName)

Added in revision 25

Call this method to grant an application all the permissions declared in its manifest.

The method works in best effort. If almost one of the requested permissions is not granted an error is returned. In case of error to check which permissions are granted use PackageManger.getPackageInfo(String packageName, int flags) with the flag PackageManager#GET_PERMISSIONS to get the PackageInfo of the application with the permissions information.

Parameters
packageName String The application to grant permissions to.
Returns
Throws
AppManagerException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int grantPermissions (String packageName, ArrayList<String> permissions)

Added in revision 25

Call this method to grant an application the specified permissions.

The method works in best effort. If almost one of the requested permissions is not granted an error is returned. In case of error to check which permissions are granted use PackageManger.getPackageInfo(String packageName, int flags) with the flag PackageManager#GET_PERMISSIONS to get the PackageInfo of the application with the permissions information.

Parameters
packageName String The application to grant permissions to.
permissions ArrayList The list of permissions to be granted.
Returns
Throws
AppManagerException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int removeBatteryOptimizationExemption (String packageName)

Added in revision 31

Call this method to remove the given application package from the device's power allowlist.

Parameters
packageName String The name of the package to be removed from the device's power allowlist.
Returns
Throws
AppManagerException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int revokePermissions (String packageName, ArrayList<String> permissions)

Added in revision 28

Call this method to revoke an application the specified permissions.

The method works in best effort. If almost one of the requested permissions is not revoked an error is returned. In case of error to check which permissions are revoked use PackageManger.getPackageInfo(String packageName, int flags) with the flag PackageManager#GET_PERMISSIONS to get the PackageInfo of the application with the permissions information.

Parameters
packageName String The application to revoke permissions to.
permissions ArrayList The list of permissions to be revoked.
Returns
Throws
AppManagerException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int setApplicationEnabledSetting (String packageName, int newState, int flags)

Added in revision 25

Call this method to set the enable setting for an application.

Parameters
packageName String The package name of the application to enable.
newState int The new enabled state for the application.
flags int Optional behaviour flags. Value is either 0 or a combination of android.content.pm.PackageManager#DONT_KILL_APP and android.content.pm.PackageManager#SYNCHRONOUS. Not expected values in combinationation with these are ignored. See for more details the Android documentation PackageManager.setApplicationEnabledSetting(String packageName, int newState, int flags).
Returns
Throws
AppManagerException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int setApplicationHidden (String packageName, boolean hidden)

Added in revision 25

Call this method to hide or unhide packages.

If the package is already hide/unhide the method returns GENERIC_ERROR.

Parameters
packageName String The name of the package to hide or unhide.
hidden boolean True if the package should be hidden, false if it should be unhidden.
Returns
Throws
AppManagerException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int setNotificationsEnabledForPackage (String packageName, boolean enabled)

Added in revision 34

Call this method to enable/disable the notifications of the given application.

Parameters
packageName StringThe package of the application for which to enable/disable notifications.
enabled booleanTrue to enable notifications, false to disable.
Returns
Throws
AppManagerException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int setStatusBarDisabled (boolean disabled)

Added in revision 31

Call this method to disable or enable the status bar.
Disabling the status bar blocks notifications and quick settings.

Parameters
disabled boolean True disables the status bar, false reenables it.
Returns
Throws
AppManagerException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int setUninstallBlocked (String packageName, boolean uninstallBlocked)

Added in revision 25

Change whether a user can uninstalling a package.

Parameters
packageName String The name of the package to change.
uninstallBlocked boolean True if the user shouldn't be able to uninstall the package.
Returns
Throws
AppManagerException in case of error, when exceptions are enabled through the ErrorManager singleton.