ILifecycle, Contextpublic class FileAbility extends Ability
IDataAbility that facilitates secure sharing of a files
associated with an app by creating a dataability://Uri for a file instead of file:/// Uri.
You can include a FileAbility in your app by specifying it entirely in Json.
To specify the FileAbility component itself, add a /Resources/rawfile/fileability.json in you app.
You should adjust path conversion rules for example, you can only
share the files in the fileability.json path.Ability.LayoutParamsHelper, Ability.WindowAttributeHelperFORM_INVISIBLE, FORM_VISIBLECONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESOUCE_ONLY, CONTEXT_RESTRICTED, MODE_APPEND, MODE_PRIVATE| 构造器 | 说明 |
|---|---|
FileAbility() |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
PacMap |
call(String method,
String arg,
PacMap extras) |
Defines a method in this Data ability (implementation depending on child classes).
|
int |
delete(Uri uri,
DataAbilityPredicates predicates) |
Deletes one or more data records.
|
String[] |
getFileTypes(Uri uri,
String mimeTypeFilter) |
Obtains the MIME type of files.
|
static File |
getFileViaUri(Uri uri) |
Convert temp Uri via File.
|
String |
getType(Uri uri) |
Obtains the MIME type matching the data specified by the URI of the Data ability.
|
static Uri |
getUriViaFile(Context context,
String Authority,
File file) |
Get Uri via File.
|
int |
insert(Uri uri,
ValuesBucket value) |
Inserts a data record into the database.
|
void |
onStart(Intent intent) |
Called back when an ability is started for initialization (it can be called only once in the entire lifecycle of
an ability).
|
FileDescriptor |
openFile(Uri uri,
String mode) |
Opens a file.
|
RawFileDescriptor |
openRawFile(Uri uri,
String mode) |
Opens a raw file.
|
ResultSet |
query(Uri uri,
String[] columns,
DataAbilityPredicates predicates) |
Queries one or more data records in the database.
|
int |
update(Uri uri,
ValuesBucket value,
DataAbilityPredicates predicates) |
Updates one or more data records in the database.
|
addActionRoute, batchInsert, cancelBackgroundRunning, connectAbility, continueAbility, continueAbility, continueAbilityReversibly, continueAbilityReversibly, createPipeFile, denormalizeUri, disconnectAbility, dispatchAccessibilityEventInfo, executeBatch, executeOperation, findComponentById, getAbilityName, getAbilityPackage, getAdmissionTransitionConcurEnabled, getAdmissionTransitionObject, getAVController, getBackTransitionConcurEnabled, getBackTransitionObject, getContinuationRegisterManager, getContinuationState, getCurrentFocus, getIntent, getLayoutParams, getLifecycle, getOriginalDeviceId, getQuitTransitionObject, getReadmissionTransitionObject, getSharedItemAdmissionTransitionObject, getSharedItemBackTransitionObject, getSharedItemQuitTransitionObject, getSharedItemReadmissionTransitionObject, getState, getVolumeTypeAdjustedByKey, getWindow, hasWindowFocus, isTemporary, isTerminating, keepBackgroundRunning, normalizeUri, onAbilityResult, onAcquireFormState, onActive, onBackground, onBackPressed, onCastTempForm, onCommand, onCommand, onConfigurationUpdated, onConnect, onCreateForm, onCreateForm, onDeleteForm, onDeleteForm, onDisconnect, onEventDispatch, onEventNotify, onForeground, onHotkeyTriggered, onInactive, onInitialized, onKeyDown, onKeyPressAndHold, onKeyUp, onLeaveForeground, onMemoryLevel, onMissionDeleted, onNewDescription, onNewIntent, onOrientationChanged, onPostActive, onPostStart, onReconnect, onRequestPermissionsFromUserResult, onRestoreAbilityState, onSaveAbilityState, onSetCaller, onStop, onStoreDataWhenConfigChange, onTopActiveAbilityChanged, onTouchEvent, onTriggerFormEvent, onTriggerFormEvent, onUnloadForm, onUpdateForm, onUpdateForm, onWindowFocusChanged, parsePredictionArgsReference, parseValuesBucketReference, postTask, reload, reverseContinueAbility, setAbilitySliceAnimator, setAdmissionTransitionConcurEnabled, setAdmissionTransitionObject, setAVController, setBackTransitionConcurEnabled, setBackTransitionObject, setFormNextRefreshTime, setIntent, setIsAmbientMode, setLayoutParams, setMainRoute, setQuitTransitionObject, setReadmissionTransitionObject, setResult, setSharedItemAdmissionTransitionObject, setSharedItemBackTransitionObject, setSharedItemQuitTransitionObject, setSharedItemReadmissionTransitionObject, setSwipeToDismiss, setUIContent, setUIContent, setVolumeTypeAdjustedByKey, setWindowBackgroundColor, shutdown, startAbility, startAbility, startAbility, startAbility, startAbilityForResult, startAbilityForResult, startAssistAbility, stopAbility, stopAssistAbility, supportHighPerformanceUI, terminateAbility, updateForm, updateForm, updateForm, updateFormattachBaseContext, canRequestPermission, compelVerifyCallerPermission, compelVerifyCallerUriPermission, compelVerifyPermission, compelVerifyPermission, compelVerifyUriPermission, compelVerifyUriPermission, compelVerifyUriPermission, createBundleContext, createParallelTaskDispatcher, createSerialTaskDispatcher, deleteFile, displayUnlockMissionMessage, getAbilityInfo, getAbilityManager, getAbilityPackageContext, getApplicationContext, getApplicationInfo, getAppType, getBundleCodePath, getBundleManager, getBundleName, getBundleResourcePath, getCacheDir, getCaller, getCallingAbility, getCallingBundle, getClassloader, getCodeCacheDir, getColor, getColorMode, getContext, getDatabaseDir, getDataDir, getDir, getDisplayOrientation, getDistributedDir, getElementName, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getGlobalTaskDispatcher, getHapModuleInfo, getIntArray, getLastStoredDataWhenConfigChanged, getLocalClassName, getMainTaskDispatcher, getNoBackupFilesDir, getPattern, getPreferencesDir, getProcessInfo, getProcessName, getResourceManager, getResourceManager, getString, getString, getStringArray, getTheme, getThemeId, getUITaskDispatcher, init, isCredentialEncryptedStorage, isDeviceEncryptedStorage, isUpdatingConfigurations, lockMission, printDrawnCompleted, requestPermissionsFromUser, restart, setColorMode, setDisplayOrientation, setPattern, setShowOnLockScreen, setTheme, setTransitionAnimation, setWakeUpScreen, startAbilities, startAbility, startAbility, startAbility, switchToCredentialEncryptedStorageContext, switchToDeviceEncryptedStorageContext, terminateAbility, terminateAbilityResult, unlockMission, verifyCallingOrSelfPermission, verifyCallingPermission, verifyPermission, verifySelfPermissionpublic void onStart(Intent intent)
AbilityMost initialization operations should be performed by calling this method. For example, you can use the
current method to call Ability.setMainRoute(java.lang.String) and
Ability.addActionRoute(java.lang.String,java.lang.String) to set the main router and action router for a Page ability.
public ResultSet query(Uri uri, String[] columns, DataAbilityPredicates predicates)
Abilityquery 在类中 Abilityuri - Indicates the database table storing the data to query.columns - Indicates the columns to be queried, in array, for example, {"name","age"}. You should define
the processing logic when this parameter is null.predicates - Indicates filter criteria. If this parameter is null, all data records will be queried by
default.public int insert(Uri uri, ValuesBucket value)
Abilitypublic int delete(Uri uri, DataAbilityPredicates predicates)
Abilitypublic int update(Uri uri, ValuesBucket value, DataAbilityPredicates predicates)
Abilityupdate 在类中 Abilityuri - Indicates the database table storing the data to update.value - Indicates the data to update. This parameter can be null.predicates - Indicates filter criteria. If this parameter is null, all data records will be updated by
default.public PacMap call(String method, String arg, PacMap extras)
Abilitypublic String getType(Uri uri)
AbilityData abilities supports general data types, including text, HTML, and JPEG.
public String[] getFileTypes(Uri uri, String mimeTypeFilter)
AbilitygetFileTypes 在类中 Abilityuri - Indicates the path of the files to obtain.mimeTypeFilter - Indicates the MIME type of the files to obtain. This parameter cannot be set to
null.
1. "*/*": Obtains all types supported by a Data ability.
2. "image/*": Obtains files whose main type is image of any subtype.
3. "*/jpg": Obtains files whose subtype is JPG of any main type.
public RawFileDescriptor openRawFile(Uri uri, String mode) throws FileNotFoundException
AbilityopenRawFile 在类中 Abilityuri - Indicates the path of the raw file to open.mode - Indicates the open mode, which can be "r" for read-only access, "w" for write-only access (erasing
whatever data is currently in the file), "wt" for write access that truncates any existing file,
"wa" for write-only access to append to any existing data, "rw" for read and write access on any
existing data, or "rwt" for read and write access that truncates any existing file.RawFileDescriptor object containing file descriptor.FileNotFoundException - Throws this exception if the raw file does not exist.public FileDescriptor openFile(Uri uri, String mode)
AbilityopenFile 在类中 Abilityuri - Indicates the path of the file to open.mode - Indicates the open mode, which can be "r" for read-only access, "w" for write-only access (erasing
whatever data is currently in the file), "wt" for write access that truncates any existing file,
"wa" for write-only access to append to any existing data, "rw" for read and write access on any
existing data, or "rwt" for read and write access that truncates any existing file.FileDescriptor object of the file descriptor.public static Uri getUriViaFile(Context context, String Authority, File file)
name - Indicates the Context object on HarmonyOS.Authority - Indicates the object on HarmonyOS.file - Indicates the ori file convert to uri.