Ability, AbilityContext, AbilityPackage, AbilitySlice, AccessibleAbility, AceAbility, AceDataAbility, AceServiceAbility, AVBrowserService, FileAbility, Fraction, FractionAbility, HostService, InputMethodAbility, IntentAbility, OffHostService, WorkSchedulerpublic interface Context
You can use Context to obtain resources, start abilities, create or obtain task dispatchers, and obtain
bundle and running information about the application.
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
CONTEXT_IGNORE_SECURITY |
Indicates the flag used with
createBundleContext(java.lang.String,int) for creating a Context object that
can always be loaded with all security restrictions ignored. |
static int |
CONTEXT_INCLUDE_CODE |
Indicates the flag used with
createBundleContext(java.lang.String,int) for creating a Context object that
includes the application code. |
static int |
CONTEXT_RESOUCE_ONLY |
|
static int |
CONTEXT_RESTRICTED |
Indicates the flag used with
createBundleContext(java.lang.String,int) for creating a Context object in
which particular features may be disabled. |
static int |
MODE_APPEND |
Indicates the append file creation mode, in which data will be written to the end of the file instead of being
erased if the file to be created already exists.
|
static int |
MODE_PRIVATE |
Indicates the default file creation mode, in which the created file is accessible only to the calling
application (or all applications sharing the same user ID).
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
boolean |
canRequestPermission(String permission) |
Confirms with the permission management module to check whether a request prompt is required for granting a
certain permission.
|
void |
compelVerifyCallerPermission(String permission,
String message) |
Checks whether a specified permission has been granted to the calling process for inter-process
communication (IPC), and throws a
SecurityException if the permission is not granted. |
void |
compelVerifyCallerUriPermission(Uri uri,
int modeFlags,
String message) |
Checks whether the calling process for IPC has the permission to access a specified URI, and throws
a
SecurityException if it does not have the permission. |
void |
compelVerifyPermission(String permission,
int pid,
int uid,
String message) |
Checks whether a specified permission has been granted to the process identified by
pid and uid,
and throws a SecurityException if the permission is not granted. |
void |
compelVerifyPermission(String permission,
String message) |
Checks whether a specified permission has been granted to the calling process, and throws
a
SecurityException if the permission is not granted. |
void |
compelVerifyUriPermission(Uri uri,
int pid,
int uid,
int modeFlags,
String message) |
Checks whether the process identified by
pid and uid has the permission to access
a specified URI, and throws a SecurityException if it does not have the permission. |
void |
compelVerifyUriPermission(Uri uri,
int modeFlags,
String message) |
Checks whether the calling process has the permission to access a specified URI, and throws
a
SecurityException if it does not have the permission. |
void |
compelVerifyUriPermission(Uri uri,
String readPermission,
String writePermission,
int pid,
int uid,
int modeFlags,
String message) |
Checks whether the process identified by
pid and uid has specified read and write permissions
as well as the permission to access a specified URI, and throws a SecurityException if it does not have
the permissions. |
boolean |
connectAbility(Intent intent,
IAbilityConnection conn) |
Connects the current ability to an ability using the
AbilityInfo.AbilityType.SERVICE
template. |
Context |
createBundleContext(String bundleName,
int flag) |
Creates a
Context object for an application with the given bundle name. |
TaskDispatcher |
createParallelTaskDispatcher(String name,
TaskPriority priority) |
Creates a parallel task dispatcher with a specified priority.
|
TaskDispatcher |
createSerialTaskDispatcher(String name,
TaskPriority priority) |
Creates a serial task dispatcher with a specified priority.
|
boolean |
deleteFile(String fileName) |
Deletes the specified private file associated with the application.
|
void |
disconnectAbility(IAbilityConnection conn) |
Disconnects the current ability from an ability using the
AbilityInfo.AbilityType.SERVICE template. |
void |
displayUnlockMissionMessage() |
Displays a system-defined message to the user, prompting the user how to exit the lock mission mode.
|
AbilityInfo |
getAbilityInfo() |
Obtains information about the current ability.
|
IAbilityManager |
getAbilityManager() |
Obtains an ability manager.
|
Context |
getAbilityPackageContext() |
Obtains the
Context object of this ability. |
Context |
getApplicationContext() |
Obtains the
Context object of the application. |
ApplicationInfo |
getApplicationInfo() |
Obtains information about the current application.
|
String |
getAppType() |
Obtains the type of this application.
|
String |
getBundleCodePath() |
Obtains the path of the package containing the current ability.
|
IBundleManager |
getBundleManager() |
Obtains an
IBundleManager instance. |
String |
getBundleName() |
Obtains the bundle name of the current ability.
|
String |
getBundleResourcePath() |
Obtains the path of the Ohos Ability Package (HAP} containing this ability.
|
File |
getCacheDir() |
Obtains the application-specific cache directory on the device's internal storage.
|
Uri |
getCaller() |
Obtains information about the caller of this ability.
|
ElementName |
getCallingAbility() |
Obtains the
ElementName of the ability that called the current ability. |
String |
getCallingBundle() |
Obtains the bundle name of the ability that called the current ability.
|
ClassLoader |
getClassloader() |
Obtains a
ClassLoader instance. |
File |
getCodeCacheDir() |
Obtains the application-specific code-cache directory on the device's internal storage.
|
int |
getColor(int resId) |
Get the color of this
Context based on the specified resource ID. |
int |
getColorMode() |
Obtains color mode.
|
File |
getDatabaseDir() |
Obtains the local database path.
|
File |
getDataDir() |
Obtains the absolute path where all private data files of this application are stored.
|
File |
getDir(String name,
int mode) |
Obtains the directory for storing custom data files of the application.
|
int |
getDisplayOrientation() |
Obtains the current display orientation of this ability.
|
File |
getDistributedDir() |
Obtains the distributed file path.
|
ElementName |
getElementName() |
Obtains the
ohos.bundle.ElementName object of the current ability. |
File |
getExternalCacheDir() |
Obtains the absolute path to the application-specific cache directory on the primary external or shared
storage device.
|
File[] |
getExternalCacheDirs() |
Obtains the absolute paths to the application-specific cache directories on all external or shared storage
devices.
|
File |
getExternalFilesDir(String type) |
Obtains the absolute path to the directory for storing files for the application on the primary external or
shared storage device.
|
File[] |
getExternalFilesDirs(String type) |
Obtains the absolute paths to the directories for storing files for the application on all external or shared
storage devices.
|
File[] |
getExternalMediaDirs() |
Obtains the application-specific media directories on all files where it can place.
|
File |
getFilesDir() |
Obtains the directory for storing files for the application on the device's internal storage.
|
TaskDispatcher |
getGlobalTaskDispatcher(TaskPriority priority) |
Obtains a global task dispatcher with a specified priority.
|
HapModuleInfo |
getHapModuleInfo() |
Obtains the
HapModuleInfo object of the application. |
int[] |
getIntArray(int resId) |
Get the integer array of this
Context based on the specified resource ID. |
Object |
getLastStoredDataWhenConfigChanged() |
Obtains the most recent data saved via
Ability.onStoreDataWhenConfigChange()
when the system configuration is changed. |
String |
getLocalClassName() |
Obtains the local class name of the ability.
|
TaskDispatcher |
getMainTaskDispatcher() |
Obtains a task dispatcher that is bound to the application main thread.
|
File |
getNoBackupFilesDir() |
Obtains the absolute path which app created and will be excluded from automatic backup to remote storage.
|
Pattern |
getPattern() |
Obtains the pattern of this
Context. |
File |
getPreferencesDir() |
Obtains the path storing the preference file of the application.
|
ProcessInfo |
getProcessInfo() |
Obtains information about the current process, including the process ID and name.
|
String |
getProcessName() |
Obtains the name of the current process.
|
ResourceManager |
getResourceManager() |
Obtains a resource manager.
|
ResourceManager |
getResourceManager(Configuration configuration) |
Obtains a resource manager based on the specified
Configuration object. |
String |
getString(int resId) |
Get the string of this
Context based on the specified resource ID. |
String |
getString(int resId,
Object... formatArgs) |
Get the string of this
Context based on the specified resource ID and formatArgs. |
String[] |
getStringArray(int resId) |
Get the string array of this
Context based on the specified resource ID. |
Theme |
getTheme() |
Obtains the theme of this
Context. |
int |
getThemeId() |
Obtains the theme id of this
Context. |
TaskDispatcher |
getUITaskDispatcher() |
Obtains a task dispatcher that is bound to the UI thread.
|
boolean |
isCredentialEncryptedStorage() |
Checks whether the context uses credential-encrypted storage.
|
boolean |
isDeviceEncryptedStorage() |
Checks whether the context uses device-protected storage.
|
boolean |
isUpdatingConfigurations() |
Checks whether the configuration of this ability is changing
|
void |
lockMission() |
Sets the application to start its ability in lock mission mode.
|
void |
printDrawnCompleted() |
Prints out the time required for the system to complete drawing this Page ability.
|
void |
requestPermissionsFromUser(String[] permissions,
int requestCode) |
Requests certain permissions from the system.
|
void |
restart() |
Restarts this ability using a new instance.
|
void |
setColorMode(int mode) |
Set color mode.
|
void |
setDisplayOrientation(AbilityInfo.DisplayOrientation newOrientation) |
Sets the display orientation of the current ability.
|
void |
setPattern(int patternId) |
Sets the pattern of this
Context based on the specified pattern ID. |
void |
setShowOnLockScreen(boolean showOnLockScreen) |
Sets whether to show this ability on top of the lock screen whenever the lock screen is displayed,
keeping the ability in the ACTIVE state.
|
void |
setTheme(int themeId) |
Sets the theme of this
Context based on the specified theme ID. |
void |
setTransitionAnimation(int enterAnim,
int exitAnim) |
Sets the transition animation between two abilities.
|
void |
setWakeUpScreen(boolean wakeUpScreen) |
Sets whether to wake up the screen when this ability is restored.
|
void |
startAbilities(Intent[] intents) |
Starts multiple abilities.
|
void |
startAbility(Intent intent,
int requestCode) |
Starts a new ability.
|
void |
startAbility(Intent intent,
int requestCode,
AbilityStartSetting abilityStartSetting) |
Starts a new ability with special ability start setting.
|
void |
startAbility(Intent intent,
AbilityStartSetting abilityStartSetting,
IAbilityStartCallback iAbilityStartCallback) |
Starts a new ability.
|
boolean |
stopAbility(Intent intent) |
Destroys another ability that uses the
AbilityInfo.AbilityType.SERVICE template. |
void |
switchToCredentialEncryptedStorageContext() |
Changes the context storage to credential-protected storage.
|
void |
switchToDeviceEncryptedStorageContext() |
Changes the context storage to device-protected storage.
|
void |
terminateAbility() |
Destroys the current ability.
|
void |
terminateAbility(int requestCode) |
Destroys another ability you had previously started by calling
Ability.startAbilityForResult(ohos.aafwk.content.Intent, int, ohos.aafwk.ability.startsetting.AbilityStartSetting) with the same requestCode passed. |
boolean |
terminateAbilityResult(int startId) |
Destroys this Service ability if the number of times it has been started equals the number represented by the
given
startId. |
void |
unlockMission() |
Unlocks this ability by exiting the lock mission mode.
|
int |
verifyCallingOrSelfPermission(String permission) |
Checks whether the calling or current process has the given permission.
|
int |
verifyCallingPermission(String permission) |
Checks whether the calling process for inter-process communication has the given permission.
|
int |
verifyPermission(String permission,
int pid,
int uid) |
Checks whether a process ID (PID) and user ID (UID) have the given permission.
|
int |
verifySelfPermission(String permission) |
Checks whether the current process has the given permission.
|
static final int CONTEXT_IGNORE_SECURITY
createBundleContext(java.lang.String,int) for creating a Context object that
can always be loaded with all security restrictions ignored.
The value is 0x00000002.
static final int CONTEXT_INCLUDE_CODE
createBundleContext(java.lang.String,int) for creating a Context object that
includes the application code.
The value is 0x00000001.
static final int CONTEXT_RESOUCE_ONLY
static final int CONTEXT_RESTRICTED
createBundleContext(java.lang.String,int) for creating a Context object in
which particular features may be disabled.
The value is 0x00000004.
static final int MODE_APPEND
static final int MODE_PRIVATE
TaskDispatcher createParallelTaskDispatcher(String name, TaskPriority priority)
Unlike a global task dispatcher created by using getGlobalTaskDispatcher(ohos.app.dispatcher.task.TaskPriority), a parallel
task dispatcher can use separate task groups to run tasks in a group in parallel and run different task groups
in sequence.
name - Indicates the task dispatcher name. This parameter is used to locate problems.priority - Indicates the priority of all tasks dispatched by the parallel task dispatcher.TaskPriority.HIGH,
TaskPriority.DEFAULT,
TaskPriority.LOWTaskDispatcher createSerialTaskDispatcher(String name, TaskPriority priority)
If you want to execute tasks in a specific sequence, use a serial task dispatcher. Otherwise, use a parallel task dispatcher.
name - Indicates the task dispatcher name. This parameter is used to locate problems.priority - Indicates the priority of all tasks dispatched by the created task dispatcher.TaskPriority.HIGH,
TaskPriority.DEFAULT,
TaskPriority.LOWTaskDispatcher getGlobalTaskDispatcher(TaskPriority priority)
You can use a global task dispatcher to dispatch tasks that are independent from each other. Do not create task groups or execution barriers on this dispatcher.
priority - Indicates the priority of all tasks dispatched by the global task dispatcher.TaskPriority.HIGH,
TaskPriority.DEFAULT,
TaskPriority.LOWTaskDispatcher getMainTaskDispatcher()
Tasks dispatched on this dispatcher are executed in sequence. Do not use this dispatcher on the main thread for running synchronous tasks, Otherwise, a deadlock occurs.
TaskDispatcher getUITaskDispatcher()
Tasks dispatched on this dispatcher are executed in sequence. Do not use this dispatcher on the UI thread for running synchronous tasks, Otherwise, a deadlock occurs.
ApplicationInfo getApplicationInfo()
The returned application information includes basic information such as the application name and application permissions.
ApplicationInfo object for the current application.ProcessInfo getProcessInfo()
ProcessInfo object for the current process.AbilityInfo getAbilityInfo()
The returned information includes the class name, bundle name, and other information about the current ability.
AbilityInfo object for the current ability.ResourceManager getResourceManager()
ResourceManager object.File getPreferencesDir()
If the preference file path does not exist, the system creates one and returns the created path.
File getDatabaseDir()
If the local database path does not exist, the system creates one and returns the created path.
File getDistributedDir()
If the distributed file path does not exist, the system creates one and returns the created path. This method is applicable only to the context of an ability rather than that of an application.
void switchToDeviceEncryptedStorageContext()
switchToDeviceEncryptedStorageContext()void switchToCredentialEncryptedStorageContext()
switchToCredentialEncryptedStorageContext()boolean isDeviceEncryptedStorage()
true if the context uses device-protected storage; returns false otherwise.isCredentialEncryptedStorage()boolean isCredentialEncryptedStorage()
true if the context uses credential-encrypted storage; returns false otherwise.isDeviceEncryptedStorage()int verifyCallingPermission(String permission)
The calling process is not the current process.
permission - Indicates the permission to check. This parameter cannot be null.0 (IBundleManager.PERMISSION_GRANTED) if the
calling process has the permission;
returns -1 (IBundleManager.PERMISSION_DENIED) otherwise.int verifySelfPermission(String permission)
You need to call requestPermissionsFromUser(java.lang.String[],int) to request a permission only if the
current process does not have the specific permission.
permission - Indicates the permission to check. This parameter cannot be null.0 (IBundleManager.PERMISSION_GRANTED) if the
current process has the permission; returns -1
(IBundleManager.PERMISSION_DENIED) otherwise.int verifyCallingOrSelfPermission(String permission)
This method checks permission for a calling process only if the call is from a remote device. Otherwise, it checks permission for the current process.
permission - Indicates the permission to check. This parameter cannot be null.0 (IBundleManager.PERMISSION_GRANTED) if the
calling or current process has the permission; returns -1
(IBundleManager.PERMISSION_DENIED) otherwise.int verifyPermission(String permission, int pid, int uid)
permission - Indicates the permission to check. This parameter cannot be null.pid - Indicates the process ID. The value must be greater than 0.uid - Indicates the user ID.0 (IBundleManager.PERMISSION_GRANTED) if the PID
and UID have the permission; returns -1
(IBundleManager.PERMISSION_DENIED) otherwise.ClassLoader getClassloader()
ClassLoader instance.
A ClassLoader instance is used to load a class, for example, to load the class of the current
ability using the class name.
ClassLoader instance.Context getApplicationContext()
Context object of the application.Context object of the application.void terminateAbility()
After the current ability using either the AbilityInfo.AbilityType.SERVICE or
AbilityInfo.AbilityType.PAGE template performs all operations, it can use this method to
destroy itself to free up memory.
void terminateAbility(int requestCode)
Ability.startAbilityForResult(ohos.aafwk.content.Intent, int, ohos.aafwk.ability.startsetting.AbilityStartSetting) with the same requestCode passed.requestCode - Indicates the request code passed for starting the ability.void displayUnlockMissionMessage()
This method takes effect only when the mission that contains this ability is in the
ohos.app.AbilityManager#LOCK_MISSION_MODE_LOCKED or
ohos.app.AbilityManager#LOCK_MISSION_MODE_PINNED state.
void lockMission()
This method takes effect only when the ability runs on the foreground.
void unlockMission()
This method takes effect only for abilities that have been put into the lock mission mode by the
lockMission() method.
String getLocalClassName()
ElementName getElementName()
ohos.bundle.ElementName object of the current ability.
This method is available only to Page abilities.ohos.bundle.ElementName object of the current ability.ElementName getCallingAbility()
ElementName of the ability that called the current ability.
You can use the obtained ElementName to check whether the calling ability is allowed
to receive the data you will send.
If you did not use Ability.startAbilityForResult(ohos.aafwk.content.Intent, int, ohos.aafwk.ability.startsetting.AbilityStartSetting) to start the calling
ability, null is returned.
ElementName of the calling ability;
returns null if no calling ability is available.String getCallingBundle()
You can use the obtained bundle name to check whether the calling ability is allowed to receive the data you will send.
If you did not use Ability.startAbilityForResult(ohos.aafwk.content.Intent, int, ohos.aafwk.ability.startsetting.AbilityStartSetting) to start the calling
ability, null is returned.
null if no calling ability is available.boolean stopAbility(Intent intent)
AbilityInfo.AbilityType.SERVICE template.
The current ability using either the AbilityInfo.AbilityType.SERVICE or
AbilityInfo.AbilityType.PAGE template can call this method to destroy another ability
that uses the AbilityInfo.AbilityType.SERVICE template. The current ability itself can
be destroyed by calling the terminateAbility() method.
intent - Indicates the Intent containing information about the ability to
destroy.true if the ability is destroyed successfully; returns false otherwise.startAbility(ohos.aafwk.content.Intent, int),
terminateAbility()void startAbility(Intent intent, int requestCode)
An ability using the AbilityInfo.AbilityType.SERVICE or
AbilityInfo.AbilityType.PAGE template uses this method to start a specific ability.
The system locates the target ability from installed abilities based on the value of the intent
parameter and then starts it. You can specify the ability to start using the intent parameter.
intent - Indicates the Intent containing information about the target
ability to start.requestCode - Indicates the request code returned after the ability using the
AbilityInfo.AbilityType.PAGE template is started. You can define
the request code to identify the results returned by abilities. The value ranges from 0 to
65535. This parameter takes effect only on abilities using the
AbilityInfo.AbilityType.PAGE template.stopAbility(ohos.aafwk.content.Intent),
terminateAbility(),
connectAbility(ohos.aafwk.content.Intent, IAbilityConnection),
disconnectAbility(IAbilityConnection)void startAbility(Intent intent, AbilityStartSetting abilityStartSetting, IAbilityStartCallback iAbilityStartCallback)
An ability using the AbilityInfo.AbilityType.SERVICE or
AbilityInfo.AbilityType.PAGE template uses this method to start a specific ability.
The system locates the target ability from installed abilities based on the value of the intent
parameter and then starts it. You can specify the ability to start using the intent parameter.
intent - Indicates the Intent containing information about the target
ability to start.abilityStartSetting - Indicates the special start setting used in starting ability.iAbilityStartCallback - Indcate the IAbilityStartCallback callback interface.stopAbility(ohos.aafwk.content.Intent),
terminateAbility(),
connectAbility(ohos.aafwk.content.Intent, IAbilityConnection),
disconnectAbility(IAbilityConnection)void startAbility(Intent intent, int requestCode, AbilityStartSetting abilityStartSetting)
An ability using the AbilityInfo.AbilityType.SERVICE or
AbilityInfo.AbilityType.PAGE template uses this method to start a specific ability.
The system locates the target ability from installed abilities based on the value of the intent
parameter and then starts it. You can specify the ability to start using the intent parameter.
intent - Indicates the Intent containing information about the target
ability to start.requestCode - Indicates the request code returned after the ability is started. You can define the
request code to identify the results returned by abilities. The value ranges from 0 to 65535.abilityStartSetting - Indicates the special start setting used in starting ability.startAbility(ohos.aafwk.content.Intent, int),
AbilityStartSettingvoid startAbilities(Intent[] intents)
An ability using the AbilityInfo.AbilityType.SERVICE or
AbilityInfo.AbilityType.PAGE template uses this method to start specific abilities.
The system distinguishes target abilities from installed abilities based on the value of the intents
parameter and then starts the target abilities. You can use the intents parameter to specify target
abilities.
intents - Indicates an array of Intent objects containing information
about the target abilities.Context createBundleContext(String bundleName, int flag)
Context object for an application with the given bundle name.
The created Context object is the same as that obtained by the specified application after it is
loaded. They have the same resources and class loader. A new Context object is returned
each time this method is called.
bundleName - Indicates the bundle name of the application.flag - Indicates the flag for creating a Context object. It can be 0, any of the following
values, or any combination of the following values: CONTEXT_IGNORE_SECURITY,
CONTEXT_INCLUDE_CODE, and CONTEXT_RESTRICTED. The value 0 indicates that
there is no restriction on creating contexts for applications.Context object created for the specified application.SecurityException - Throws this exception if the requested Context cannot be loaded to the caller's
process for security reasons. To resolve this exception, you can add
CONTEXT_IGNORE_SECURITY to the value of flag.boolean canRequestPermission(String permission)
You need to call the current method to check whether a prompt is required before calling
requestPermissionsFromUser(java.lang.String[],int) to request a permission. If a prompt is not required,
permission request will not be initiated.
permission - Indicates the permission to be queried. This parameter cannot be null.true if the current application does not have the permission and the user does not
turn off further requests; returns false if the current application already has the permission,
the permission is rejected by the system, or the permission is denied by the user and the user has turned
off further requests.void requestPermissionsFromUser(String[] permissions, int requestCode)
This method is called for permission request. This is an asynchronous method. When it is executed, the
Ability.onRequestPermissionsFromUserResult(int, String[], int[]) method will be
called back.
permissions - Indicates the list of permissions to be requested. This parameter cannot be null.requestCode - Indicates the request code to be passed to the
Ability.onRequestPermissionsFromUserResult(int, String[],
int[]) callback method. This code cannot be a negative number.IllegalArgumentException - if requestCode is negative.boolean connectAbility(Intent intent, IAbilityConnection conn)
AbilityInfo.AbilityType.SERVICE
template.
This method can be called by an ability using either the
AbilityInfo.AbilityType.SERVICE or
AbilityInfo.AbilityType.PAGE template, but the destination of the connection must be an
ability using the AbilityInfo.AbilityType.SERVICE template. You must implement the
IAbilityConnection interface to obtain the proxy of the target ability after it is connected.
intent - Indicates the Intent containing information about the ability to
connect.conn - Indicates the callback object when the target ability is connected.true if the connection is successful; returns false otherwise.void disconnectAbility(IAbilityConnection conn)
AbilityInfo.AbilityType.SERVICE template.
This method can be called by an ability using either the
AbilityInfo.AbilityType.SERVICE or
AbilityInfo.AbilityType.PAGE template, but the destination of the connection to
disconnect must be an ability using the AbilityInfo.AbilityType.SERVICE template.
conn - Indicates the IAbilityConnection callback object passed by
connectAbility(ohos.aafwk.content.Intent,ohos.aafwk.ability.IAbilityConnection) after the connection
is set up. The IAbilityConnection object uniquely identifies a connection between two
abilities.connectAbility(ohos.aafwk.content.Intent, IAbilityConnection)void setDisplayOrientation(AbilityInfo.DisplayOrientation newOrientation)
The setting takes effect only for abilities using the AbilityInfo.AbilityType.PAGE
template.
newOrientation - Indicates the new orientation for the current ability.IBundleManager getBundleManager()
IBundleManager instance.
You can use this instance to obtain information about the application bundle.
IBundleManager instance.String getBundleName()
String getBundleCodePath()
The returned path contains the resources, source code, and configuration files of a module.
String getBundleResourcePath()
File getDataDir()
File getCacheDir()
The system automatically deletes files from the cache directory if disk space is required elsewhere on the device. Older files are always deleted first.
getDir(String, int),
getExternalCacheDir()File getCodeCacheDir()
The system will delete any files stored in this location both when your specific application is upgraded, and when the entire platform is upgraded.
File[] getExternalMediaDirs()
The system will delete all these files when your specific application is uninstalled.
File getNoBackupFilesDir()
The returned path maybe changed if the application is moved to an adopted storage device.
File getFilesDir()
getDir(String, int)File getDir(String name, int mode)
You can use the returned File object to create and access files in this directory. The files can be
accessible only by the current application.
name - Indicates the name of the directory to retrieve. This directory is created as part of your
application data.mode - Indicates the file operating mode. The value can be 0 or a combination of
MODE_PRIVATE.File object for the requested directory.File getExternalCacheDir()
The application can place its cache files in this directory.
null if the external or shared storage device is temporarily unavailable.getCacheDir(),
getExternalCacheDirs()File[] getExternalCacheDirs()
The application can place its cache files in these directories.
null if the external or shared storage devices are temporarily
unavailable. The first path returned is the same as that returned by getExternalCacheDir().getExternalCacheDir()File getExternalFilesDir(String type)
The application can place its persistent files in this directory.
type - Indicates the type of the file directory to return. This parameter can be null for the following
directory or subdirectory: Environment.DIRECTORY_PICTURES,
Environment.DIRECTORY_DOCUMENTS,
Environment.DIRECTORY_DOWNLOADS,
Environment.DIRECTORY_MOVIES, or
Environment.DIRECTORY_MUSIC type.null if the external or shared storage device is temporarily unavailable.getFilesDir(),
getExternalFilesDirs(String)File[] getExternalFilesDirs(String type)
The application can place its persistent files in these directories.
type - Indicates the type of the file directories to return. This parameter can be null for the following
directory or subdirectory: Environment.DIRECTORY_PICTURES,
Environment.DIRECTORY_DOCUMENTS,
Environment.DIRECTORY_DOWNLOADS,
Environment.DIRECTORY_MOVIES, or
Environment.DIRECTORY_MUSIC type.null if the external or shared storage devices are temporarily unavailable.
The first path returned is the same as that returned by getExternalFilesDir(java.lang.String).getExternalFilesDir(String)boolean deleteFile(String fileName)
fileName - Indicates the name of the file to delete. The file name cannot contain path separators.true if the file is deleted successfully; returns false otherwise.IllegalArgumentException - Throws this exception if fileName contains path separators.IAbilityManager getAbilityManager()
The ability manager provides information about running processes and memory usage of an application.
IAbilityManager instance.boolean terminateAbilityResult(int startId)
startId. This method is the same as calling terminateAbility() to destroy this Service
ability, except that this method helps you avoid destroying it if a client has requested a Service
ability startup in Ability.onCommand(ohos.aafwk.content.Intent, boolean) but you are unaware of it.startId - Indicates the number of startup times of this Service ability passed to
Ability.onCommand(ohos.aafwk.content.Intent, boolean). The startId is
incremented by 1 every time this ability is started. For example,
if this ability has been started for six times, the value of startId is 6.true if the startId matches the number of startup times
and this Service ability will be destroyed; returns false otherwise.int getDisplayOrientation()
void setShowOnLockScreen(boolean showOnLockScreen)
showOnLockScreen - Specifies whether to show this ability on top of the lock screen. The value true
means to show it on the lock screen, and the value false means not.void setWakeUpScreen(boolean wakeUpScreen)
This method takes effect only on abilities visible to users after the screen is woken up.
wakeUpScreen - Specifies whether to wake up the screen. The value true means to wake it up,
and the value false means not.void restart()
This method takes effect only for abilities using the AbilityInfo.AbilityType.PAGE
template.
void setTransitionAnimation(int enterAnim,
int exitAnim)
This method must be called after startAbility(ohos.aafwk.content.Intent,int) is called.
enterAnim - Indicates the resource ID of the animation for the incoming ability.exitAnim - Indicates the resource ID of the animation for the outgoing ability.boolean isUpdatingConfigurations()
Generally, such change information is used in Ability.onStop() for determining
how to handle resources referenced by this ability.
true if the configuration is changing, for example, if the display orientation of the
device is changing; returns false otherwise.void setTheme(int themeId)
Context based on the specified theme ID.themeId - Indicates the resource ID of the theme to set.Theme getTheme()
Context.
This method is valid only when a theme has been set by calling setTheme(int).
Context.int getThemeId()
Context.Context.void setPattern(int patternId)
Context based on the specified pattern ID.patternId - Indicates the resource ID of the pattern to set.Pattern getPattern()
Context.
This method is valid only when a pattern has been set by calling setPattern(int).
Context.String getAppType()
system if this application is a system application;
returns normal if it is released in Ohos AppGallery;
returns other if it is released by a third-party vendor;
returns an empty string if the query fails.ResourceManager getResourceManager(Configuration configuration)
Configuration object.configuration - Indicates the Configuration object containing the resource configuration
information.ResourceManager object.Object getLastStoredDataWhenConfigChanged()
Ability.onStoreDataWhenConfigChange()
when the system configuration is changed.void printDrawnCompleted()
void compelVerifyPermission(String permission, String message)
SecurityException if the permission is not granted.permission - Indicates the permission to check.message - Indicates the information to be displayed in the SecurityEexception if it is thrown.SecurityException - Throws this exception if the calling process does not have the specified permission.void compelVerifyUriPermission(Uri uri, int modeFlags, String message)
SecurityException if it does not have the permission.uri - Indicates the URI to check. This parameter cannot be null.modeFlags - Indicates the access modes to check. The value can be
ohos.aafwk.content.Intent#FLAG_AUTH_READ_URI_PERMISSION,
ohos.aafwk.content.Intent#FLAG_AUTH_WRITE_URI_PERMISSION, or a combination of them.message - Indicates the information to be displayed in the SecurityEexception if it is thrown.SecurityException - Throws this exception if the calling process does not have the permission.void compelVerifyCallerPermission(String permission, String message)
SecurityException if the permission is not granted.
This method also throws a SecurityException if you are currently not involved in an IPC.permission - Indicates the permission to check.message - Indicates the information to be displayed in the SecurityEexception if it is thrown.SecurityException - Throws this exception if the calling process does not have the specified permission
or if you are currently not involved in an IPC.void compelVerifyCallerUriPermission(Uri uri, int modeFlags, String message)
SecurityException if it does not have the permission.
This method also throws a SecurityException if you are currently not involved in an IPC.uri - Indicates the URI to check. This parameter cannot be null.modeFlags - Indicates the access modes to check. The value can be
ohos.aafwk.content.Intent#FLAG_AUTH_READ_URI_PERMISSION,
ohos.aafwk.content.Intent#FLAG_AUTH_WRITE_URI_PERMISSION, or a combination of them.message - Indicates the information to be displayed in the SecurityEexception if it is thrown.SecurityException - Throws this exception if the calling process does not have the permission or
if you are currently not involved in an IPC.void compelVerifyPermission(String permission, int pid, int uid, String message)
pid and uid,
and throws a SecurityException if the permission is not granted.permission - Indicates the permission to check.pid - Indicates the ID of the process to check.uid - Indicates the UID of the process to check.message - Indicates the information to be displayed in the SecurityEexception if it is thrown.SecurityException - Throws this exception if the process with the specified PID and UID does not have
the specified permission.void compelVerifyUriPermission(Uri uri, int pid, int uid, int modeFlags, String message)
pid and uid has the permission to access
a specified URI, and throws a SecurityException if it does not have the permission.uri - Indicates the URI to check. This parameter cannot be null.pid - Indicates the ID of the process to check.uid - Indicates the UID of the process to check.modeFlags - Indicates the access modes to check. The value can be
ohos.aafwk.content.Intent#FLAG_AUTH_READ_URI_PERMISSION,
ohos.aafwk.content.Intent#FLAG_AUTH_WRITE_URI_PERMISSION, or a combination of them.message - Indicates the information to be displayed in the SecurityEexception if it is thrown.SecurityException - Throws this exception if the process with the specified PID and UID does not have
the permission.void compelVerifyUriPermission(Uri uri, String readPermission, String writePermission, int pid, int uid, int modeFlags, String message)
pid and uid has specified read and write permissions
as well as the permission to access a specified URI, and throws a SecurityException if it does not have
the permissions.uri - Indicates the URI to check. This parameter cannot be null.readPermission - Indicates the read permission to check.writePermission - Indicates the write permission to check.pid - Indicates the ID of the process to check.uid - Indicates the UID of the process to check.modeFlags - Indicates the access modes to check. The value can be
ohos.aafwk.content.Intent#FLAG_AUTH_READ_URI_PERMISSION,
ohos.aafwk.content.Intent#FLAG_AUTH_WRITE_URI_PERMISSION, or a combination of them.message - Indicates the information to be displayed in the SecurityEexception if it is thrown.SecurityException - Throws this exception if the process with the specified PID and UID does not have
the permissions.int getColor(int resId)
Context based on the specified resource ID.resId - Indicates the resource ID of the color to get.Context.String getString(int resId)
Context based on the specified resource ID.resId - Indicates the resource ID of the string to get.Context.String getString(int resId, Object... formatArgs)
Context based on the specified resource ID and formatArgs.resId - Indicates the resource ID of the string to get.formatArgs - Indicates the formatted objects used for substitution.Context.String[] getStringArray(int resId)
Context based on the specified resource ID.resId - Indicates the resource ID of the string array to get.Context.int[] getIntArray(int resId)
Context based on the specified resource ID.resId - Indicates the resource ID of the integer array to get.Context.String getProcessName()
Context getAbilityPackageContext()
Context object of this ability.
This method cannot be used to obtain the context of the application.
Context object of this ability.HapModuleInfo getHapModuleInfo()
HapModuleInfo object of the application.HapModuleInfo object of the application.Uri getCaller()
void setColorMode(int mode)
mode - the value of color mode.int getColorMode()