harmony-utils

harmony-utils(API12+)
🏆Introduction and Description
harmony-utils A HarmonyOS tool library with rich features and extremely easy to use, with the help of many practical tools, is committed to helping developers quickly build Hongmeng applications. Its encapsulated tools cover APP, device, screen, authorization, notification, inter-thread communication, pop-up frames, toast, biometric authentication, user preferences, taking photos, albums, scanning codes, files, logs, exception capture, characters, strings, numbers, collections, dates, random, base64, encryption, decryption, JSON and other functions, which can meet various development needs.
picker_utils It is a sub-store split by harmony-utils, including PickerUtil, PhotoHelper, and ScanUtil.
📚 Warm reminder: 📕 Harmony-utils is a lightweight framework that integrates more than 50 tool classes, but it is only 130KB in size. Achieve the ultimate balance between tool count and lightweight performance. 📙 Starting from version 1.3.2, the methods in the harmony-utils tool library will no longer be directly discarded. Please feel free to use it in third-party libraries and projects. 📒 In the update record, each version number has the corresponding minimum development tool version, such as: "DevEco Studio 5.1.0 Release". 📗 Please read the documentation carefully and view the use case before using the framework. 🙏 📘 See, please! Follow the official account of "Elder Tong" quickly, and you are waiting for you to unlock it. 📔 Creation is not easy, please give Elder Tong a thumbs up 👍github❤️ gitee❤️ 三方库❤️
🌞Download, installation and use instructions 🙏
ohpm i @pura/harmony-utils
OpenHarmony ohpm environment configuration and more, please refer to如何安装 OpenHarmony ohpm 包
全局初始化方法,从1.2.0版本开始,在UIAbility的onCreate方法中初始化 AppUtil.init()
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
AppUtil.init(this.context);
}
📂Module Introduction
Module | Introduction |
AppUtil | APP-related tool categories |
DeviceUtil | Device-related tools |
WindowUtil | Window related tool classes |
DisplayUtil | Screen related tools |
PermissionUtil | Application Authorization Tools |
AuthUtil | Mobile phone biometric authentication (fingerprint, face, password) tools |
NetworkUtil | Network related tools |
FileUtil | File operation related tool categories |
ImageUtil | Picture-related tools |
PreviewUtil | File Preview Tools |
LocationUtil | Positioning Tool Class (WGS-84 Coordinate System) |
LogUtil | Log Tools |
CrashUtil | Global exception capture, crash log collection |
EmitterUtil | Emitter tool class (for inter-thread communication) |
WantUtil | Want Tools |
KvUtil | Key-value database tool class |
PreferencesUtil | Preferences (User Preferences) Tool Class |
CacheUtil | Cache Tools |
LRUCacheUtil | LRUCache Cache Tool Class |
NotificationUtil | Notification Tools |
SnapshotUtil | Component screenshot and window screenshot tool class. |
KeyboardUtil | Keyboard Tools |
PasteboardUtil | Clipboard Tools |
AssetUtil | Key Asset Storage Service Tools |
ResUtil | Resource Tools |
ObjectUtil | Object Tool Class |
JSONUtil | JSON Tool Class |
DateUtil | Date Tools |
Base64Util | Base64 Tools |
StrUtil | String Tool Class |
CharUtil | Character Tools |
NumberUtil | number tool class |
ArrayUtil | Collection Tools |
RandomUtil | Random Tools |
RegexUtil | Regular Tools |
TypeUtil | Type Checking Tool Class |
FormatUtil | Format Tools |
ClickUtil | Throttle, anti-shake tool class (used to click events to prevent buttons from being clicked repeatedly) |
TempUtil | Temperature conversion tool category |
DialogUtil | Pop-up tool class (AlertDialog) |
ToastUtil | Toast Tools (promptAction) |
SM2, SM3, SM4, AES, DES, RSA, MD5, SHA, ECDSA, CryptoUtil, CryptoHelper | Encryption and decryption algorithm tool class CryptoUtil: Encryption and decryption utility class, used with each encryption module. CryptoHelper: Encrypt and decrypt data type conversion. |
PickerUtil | Selection and saving of photos, files (files, pictures, videos, audio), tools.拆分至 picker_utils |
PhotoHelper | Photo Album related tool category.拆分至 picker_utils |
ScanUtil | Code tool category (scan code, code image generation, picture identification).拆分至 picker_utils |
AppUtil (APP-related tool class)使用案例
Methods | Introduction |
init | Initialization method, cache global variables, and initialize the method in UIAbility's onCreate method |
isApiSupported | Check whether the API version is safe |
getApplicationContext | Ability to get application-level context, ApplicationContext |
getContext | Get context, common.UIAbilityContext |
getUIContext | Get UIContext |
getWindowStage | Get WindowStage |
getMainWindow | Get the main window |
getConfiguration | Get the application's Configuration |
setGrayScale | Set grayscale, APP has one-click graying |
setColorMode | Set the applied color mode. Only main thread calls are supported. Set color mode, including: dark mode, light mode, no setting (follow system) |
getColorMode | Get the color mode of the application |
setFont | Set the font type of the application. Only main thread calls are supported |
setFontSizeScale | Set the applied font size scaling ratio. Only main thread calls are supported. |
getFontSizeScale | Get the app font size scaling |
setLanguage | Set the language of the application |
getLanguage | Get the language of the application |
setSupportedProcessCache | Set whether the application itself supports cache and starts quickly |
clearUpApplicationData | Clean up the application's own data and revoke the application's permissions to the user. |
killAllProcesses | Terminate all processes of the application, and the application life cycle will not be completed normally when the process exits. |
restartApp | Restart the app and pull up the specified UIAbility of itself. The onDestroy callback will not be received during restart. |
exit | Actively exit the entire application; after calling this method, the tasks in the task center will not be cleaned by default. If you need to clean it, you need to configure removeMissionAfterTerminate to true. |
getRunningProcessInformation | Get information about running the process |
onApplicationStateChange | Register listening to changes before and after the current application |
offApplicationStateChange | Cancel listening to the application's front and backend switching events |
onEnvironment | Register monitoring of system environment changes |
offEnvironment | Cancel monitoring of system environment changes |
onAbilityLifecycle | Register to listen for in-app lifecycle |
offAbilityLifecycle | Cancel listen for in-app lifecycle |
getKeyboardAvoidMode | Get page avoidance mode when virtual keyboard is lifted (OFFSET-up mode, RESIZE-compression mode) |
setKeyboardAvoidMode | Set the page avoidance mode when the virtual keyboard pops up |
isPortrait | Is the current device displayed in a vertical screen |
isLandscape | Is the current device displayed in landscape mode |
getStatusBarHeight | Get the height of the status bar in px |
getNavigationIndicatorHeight | Get the height of the bottom navigation bar in px. |
setStatusBar | Set the immersive status bar (need to be used with getStatusBarHeight and getNavigationIndicatorHeight) |
getBundleInfo getBundleInfoSync | Get the BundleInfo for the current application |
getAppInfo getAppInfoSync | Get application configuration information |
getSignatureInfo getSignatureInfoSync | Get the signature information of the application package |
getBundleName | Get the name of the application package |
getVersionCode | Get application version number |
getVersionName | Get application version name |
getTargetVersion | Get the target version of the application running |
getInstallTime | Application Package Installation Time |
getUpdateTime | Application Package Update Time |
getAppProvisionType | Get the type of application signature certificate file, divided into two types: debug and release. |
debug | Indicates whether the application is in debug mode. A value of true means the application is in debug mode. A value of false means the application is in non-debug mode. |
DeviceUtil (device-related tool class)使用案例
Methods | Introduction |
getDeviceId | Get the device ID (it remains unchanged after uninstalling the APP, and permissions are required: ohos.permission.STORE_PERSISTENT_DATA) |
deleteDeviceId | Remove Device ID |
getODID | Get the developer's anonymous device identifier, ODID. |
getOAID | Get the open anonymous device identifier, OAID. |
getAAID | Get AAID. |
deleteAAID | DeleteAAID. |
getSerial | Get the device serial number. Description: Can be used as a unique identification code for the device. Example: The serial number varies with the device. |
getUdid | Get the device Udid. |
getBrand | Get the device brand name. Example: HUAWEI. |
getProductModel | Get certified model. Example: ALN-AL00. |
getBrandModel | Get the device brand name Certified model. Example: HUAWEI ALN-AL00. |
getMarketName | Get the external product series name. Example: HUAWEI Mate 60 Pro. |
getHardwareModel | Get the hardware version number. Example: HL1CMSM. |
getManufacture | Get the device manufacturer name. Example: HUAWEI. |
getOsFullName | Get system version |
getDisplayVersion | Get the product version. Example: ALN-AL00 5.0.0.1(XXX) |
getBuildVersion | Get the Build version number, identifying the version number of the compiled and built |
getSdkApiVersion | Get the system software API version. Example: 12 |
getOsVersion | Get the OS version number (Major version number, example: 5; Senior version number, example: 0; Feature version number, example: 0). |
getAbiList | Application binary interface (Abi). Example: arm64-v8a |
getOsReleaseType | Get the system's publishing type, the values are: Canary, Beta, Release |
getDeviceType | Get the current device type |
getDeviceTypeStr | Get the current device type and return the string. |
getConfiguration getConfigurationSync | Get the device's Configuration |
getDirection | Get the current device screen direction |
getDeviceCapability getDeviceCapabilitySync | Get DeviceCapability for DeviceCapability |
getScreenDensity | Get the current device screen density |
getBatterySOC | Get the percentage of battery remaining in the current device. |
getBatteryCapacityLevel | Get the current device battery level. |
getHealthStatus | Get the current health status of the device battery. |
getBatteryTemperature | Get the current device battery temperature, unit 0.1 degrees Celsius. |
getVoltage | Get the voltage of the current device battery, unit to microvolts. |
getNowCurrent | Get the current of the current device battery in milliamperes. |
isActive | Detect whether the current device is active. Devices with screens are in a light screen state, while devices without screens are in a non-sleep state. |
isStandby | Detect whether the current device enters standby low-power battery life mode. |
getPowerMode | Get the power mode of the current device. |
startVibration | Turn on device vibration |
stopVibration | Stop the device vibration (according to VIBRATOR_STOP_MODE_TIME mode) |
WindowUtil (window-related tool class)使用案例
Methods | Introduction |
setPreferredOrientation | Set the display direction properties of the window |
getPreferredOrientation | Get the display direction property of the window, and the main window is called. |
setWindowPrivacyMode | Set whether the window is in Privacy Mode. For a window set to privacy mode, the content of the window will not be screenshot or recorded |
isPrivacyMode | Whether the window is privacy mode, the default main window. |
setWindowLayoutFullScreen | Set whether the layout of the window is an immersive layout (the status bar and navigation bar of the immersive layout are still displayed) |
isLayoutFullScreen | Determine whether the window is immersive, the default main window. |
setWindowSystemBarProperties | Set the properties of the three-key navigation bar and status bar in the main window. |
getWindowSystemBarProperties | Get the properties of the three-key navigation bar and status bar in the main window. |
setImmersiveModeEnabledState | Set whether the current window is turned on to immersive layout. This call will not change the window mode and window size. |
getImmersiveModeEnabledState | Check whether the current window has enabled immersive layout. |
setWindowGrayScale | Set window grayscale. This interface needs to be called after calling loadContent() or setUIContent() to make the window load the page content. |
setWindowBackgroundColor | Set the background color of the window. Under the Stage model, this interface needs to be used after the loadContent() or setUIContent() call takes effect |
setWindowSystemBarEnable | Set the visible mode of the three-key navigation bar, status bar, and bottom navigation bar in the main window. The status bar and bottom navigation bar are controlled through status and the three-key navigation bar are controlled through navigation. |
setSpecificSystemBarEnabled | Set the display and hide of the three-key navigation bar, status bar, and bottom navigation bar in the main window. |
setWindowKeepScreenOn | Set whether the screen is always on |
isKeepScreenOn | Is the screen always lit |
setWindowBrightness | Set screen brightness value |
getBrightness | Get screen brightness. This parameter is a floating point number, and the brightness range that can be set is [0.0, 1.0], which indicates the maximum brightness value when taken 1.0. If the window does not set the brightness value, it means that the brightness follows the system, and the brightness value obtained at this time is -1. |
setWindowFocusable | Sets the scene where the window is focused by clicking or other means, whether the window supports switching the window focus from the focus window before clicking to the window |
isFocusable | Whether the window is focused, the default main window. |
setWindowTouchable | Set whether the window is touchable |
isTouchable | Whether the window is touchable, the default main window. |
getWindowProperties | Get the properties of the current window, the default main window. |
getWindowAvoidArea | Get the area to which the current application window content is evaded. For example, when the system bar area, notch screen area, gesture area, soft keyboard area, etc. overlap with the window content, the window content needs to be avoided. |
getWindowType | Gets the window type, default main window. |
getWindowStatus | Get the current application window mode |
isFullScreen | Determine whether the window is full screen, the default main window. |
isFocused | Determine whether the current window has been focused |
isTransparent | Whether the window is transparent, the default main window. |
isWindowShowing | Determine whether the current window has been displayed, the default main window. |
isWindowSupportWideGamut | Determine whether the current window supports wide color gamut mode, the default main window. |
setDialogBackGestureEnabled | Set whether the modal window responds to gestures and returns an event, and calls to non-modal windows return an error code |
setGestureBackEnabled | Set whether the return gesture function is disabled in the current window. It only takes effect in full screen mode of the main window, and does not take effect in 2in1 device. |
isGestureBackEnabled | Get whether the return gesture function is disabled in the current window. It only takes effect in full screen mode of the main window, and the 2in1 device does not take effect. |
createWindow | Create a child window or system window and use Promise asynchronous callback. |
findWindow | Find the window corresponding to name. |
getLastWindow | Get the topmost subwindow in the current application. If there is no application subwindow, it returns to the application main window. |
shiftAppWindowFocus | Transfer window focus from the source window to the target window in the same application, only the focus transfer of the main window and child window of the application is supported. |
DisplayUtil (screen related tool class)使用案例
Methods | Introduction |
getDefaultDisplaySync | Get the current default display object |
getPrimaryDisplaySync | Get home screen information. Devices other than 2in1 obtain the Display object with the device's own screen; when the 2in1 device connects to the external screen, it obtains the Display object with the current home screen; when the 2in1 device does not have an external screen, it obtains the Display object with the screen. |
getAllDisplays | Get all current display objects, use Promise asynchronous callback |
getWidth | Get the screen width of the device in px |
getHeight | Get the screen height of the device in px |
getOrientation | Get the current direction of the device |
getDisplayState | Get the device's status |
getCutoutRect | Get information on unavailable screen areas such as hole-punch screen, notch screen, waterfall screen, etc. It is recommended to apply layout to avoid this area |
getCutoutHeight | Get the height of unavailable screen areas such as hole-punch screen, notch screen, unit is px |
isFoldable | Check if the device is foldable |
getFoldStatus | Get the current folding status of the foldable device |
getFoldDisplayMode | Get the display mode of the foldable device |
onFoldStatusChange | Turn on monitoring of folding state changes in folding device |
offFoldStatusChange | Turn off monitoring of folding state changes in folding device |
onFoldAngleChange | Turn on monitoring of folding angle changes in folding device. If it is a bifold shaft device, there are two angle values; when the charging port is facing downward, the folding shaft one and folding shaft two are respectively from right to left. |
offFoldAngleChange | Close the monitoring of folding angle changes in folding equipment |
isCaptured | Check whether the device is taking screenshots, projecting, or recording screens. |
onCaptureStatusChange | Turn on monitoring of screen capture, projection, and recording status changes. |
offCaptureStatusChange | Close monitoring of changes in screen capture, projection, and recording status. |
PermissionUtil (apply for authorization tool category)使用案例
Methods | Introduction |
requestPermissionsEasy | Apply for authorization, and apply for authorization to the user again after refusing (apply for permission, it is recommended to use this method). |
checkPermissions | Verify that it is currently authorized |
checkRequestPermissions | After verifying whether to authorize and apply for authorization |
requestPermissions | Apply for authorization |
requestPermissionOnSetting | Secondary application for authorization to the user (single permissions or read and write permission groups, this method is recommended). |
requestPermissionOnSettingEasy | Secondary application for authorization to the user (this method is recommended for multiple permissions). |
requestGlobalSwitch | Used to UIAbility/UIExtensionAbility to pull up the global switch to set the pop-up box. In some cases, recording, taking photos and other functions are disabled. The application can pull up this box and ask the user to agree to enable the corresponding functions. If the current global switch status is on, the pop-up box will not be pulled up. |
AuthUtil (biological authentication (fingerprint, face, password) tool category for mobile phones)使用案例
Methods | Introduction |
getAvailableStatus | Query whether the authentication capability of the specified type and level supports |
onStartEasy | Start Authentication, Use fingerprint and password authentication |
onStart | Start authentication, user-specified type authentication |
cancel | cancel |
generateChallenge | Generate Challenge to prevent replay attacks |
getErrorMsg | Get error msg |
NetworkUtil (network-related tool class)使用案例
Methods | Introduction |
isDefaultNetMetered isDefaultNetMeteredSync | Check whether the current data traffic usage on the network is metered |
hasDefaultNet hasDefaultNetSync | Check whether the default data network is activated |
getDefaultNet getDefaultNetSync | Get the default activated data network |
getAppNet getAppNetSync | Get App-bound network information |
getAllNets getAllNetsSync | Get a list of all connected networks |
isNetworkAvailable | Determine whether the current device network is available |
hasNetMobile | Determine whether the current network is a cellular network (mobile network). |
hasNetWiFi | Determine whether the current network is a Wi-Fi network. |
hasNetEthernet | Determine whether the current network is an Ethernet network. |
hasNetVPN | Determine whether the current network is a VPN network. |
hasNetBearType | Whether the specified network exists |
getNetBearTypes | Get the network type, the array only contains one specific network type. |
getNetBearType | Get network type |
getNetCapabilities getNetCapabilitiesSync | Get the capability information of the network corresponding to netHandle |
getConnectionProperties getConnectionPropertiesSync | Get the connection information of the network corresponding to netHandle |
getIpAddress | Get the IP address of the current device (after the device is connected to Wi-Fi) |
register | Subscribe to notifications of specified network status changes, support multi-event listening callbacks |
unregister | Unsubscribe to notifications about default network status changes |
isNRSupported | Determine whether the current device supports NR (New Radio). That is 5G. |
isRadioOn | Determine whether Radio is open |
getPrimarySlotId | Get the index number of the card slot where the main card is located |
getOperatorName | Get operator name |
getNetworkState | Get network status |
getNetworkSelectionMode | Get the current network selection mode |
getSignalInformation | Get the list of registered network signal strength information corresponding to the specified SIM card slot. |
getNetworkType | Get network type |
getNetworkTypeStr | Get the network type and return the character type. |
getDefaultCellularDataSlotId getDefaultCellularDataSlotIdSync | SIM card to get default mobile data |
getCellularDataFlowType | Get the up and down state of cellular data services |
getCellularDataState | Get the connection status of the packet switching domain (PS domain) |
isCellularDataEnabled isCellularDataEnabledSync | Check whether cellular data service is enabled |
isCellularDataRoamingEnabled isCellularDataRoamingEnabledSync | Check whether cellular data services are enabled |
getDefaultCellularDataSimId | Get the SIM card ID of the default mobile data. Bind with SIM card, incrementing from 1. |
isSimActive isSimActiveSync | Get whether the SIM card is activated when the specified card slot is activated |
hasSimCard hasSimCardSync | Get whether the SIM card is inserted into the specified card slot |
getMaxSimCount | Get the number of card slots |
getSimOperatorNumeric getSimOperatorNumericSync | Get the home PLMN (Public Land Mobile Network) number of the SIM card in the specified card slot. |
getSimSpn getSimSpnSync | Get the service provider name of the SIM card specified in the card slot |
getSimState getSimStateSync | Get the SIM card status of the specified card slot |
getCardType getCardTypeSync | Get the card type of the SIM card in the specified card slot |
FileUtil (file operation related tool class)使用案例
Methods | Introduction | ||||||||||
getFilesDirPath | Get the folder path or file path in the file directory | ||||||||||
getCacheDirPath | Get the folder path or file path in the cache directory | ||||||||||
getTempDirPath | Get the folder path or file path in the temporary directory | ||||||||||
hasDirPath | Determine whether it is the complete path | ||||||||||
getFileUri | Get FileUri through URI or path | ||||||||||
getFileName | Get file name through URI or path | ||||||||||
getFilePath | Get file path through URI or path | ||||||||||
getParentUri | Get the URI of the corresponding file parent directory through URI or path | ||||||||||
getParentPath | Get the path name of the corresponding file parent directory through a URI or path | ||||||||||
getUriFromPath | Get file URI in synchronous way | ||||||||||
getFileExtention | Get file suffix based on file name | ||||||||||
getFileDirSize | Get the size of all files in the specified folder or the specified file size | ||||||||||
isFile | Determine whether a file is a normal file | ||||||||||
isDirectory | Determine whether the file is a directory | ||||||||||
rename renameSync | Rename file or folder, use Promise asynchronous callback | ||||||||||
mkdir mkdirSync | Create a directory. When recursion is specified as true, you can create a directory at multiple levels | ||||||||||
rmdir rmdirSync | Delete the entire directory and use Promise asynchronous callback | ||||||||||
unlink unlinkSync | Delete a single file, use Promise asynchronous callback | ||||||||||
access accessSync | Check whether the file exists and use Promise asynchronous callback | ||||||||||
open openSync | Open file, support using URI to open files | ||||||||||
read readSync | Read data from file | ||||||||||
readText readTextSync | Read files based on text (that is, directly read the text content of the files) | ||||||||||
write writeSync | Write data to file | ||||||||||
writeEasy | Write data to a file and close the file | ||||||||||
close closeSync | Close File | ||||||||||
listFile listFileSync | List all file names in the folder, supports recursive listing of all file names (including subdirectories), supports file filtering | ||||||||||
stat statSync | Get file detailed attribute information | ||||||||||
copy | Copy files or directories, support copy progress monitoring | ||||||||||
copyFile copyFileSync | Copy File | ||||||||||
moveFile moveFileSync | Move File | ||||||||||
moveDir moveDirSync | Move the source folder to the destination path | ||||||||||
truncate truncateSync | Truncate File | ||||||||||
lstat lstatSync | Get link file information | ||||||||||
fsync fsyncSync | Synchronize file data | ||||||||||
fdatasync fdatasyncSync | Implement file content data synchronization | ||||||||||
createStream createStreamSync | Open file stream based on file path | ||||||||||
fdopenStream fdopenStreamSync | Open file stream based on file descriptor | ||||||||||
mkdtemp mkdtempSync | Create a temporary directory | ||||||||||
dup | Convert file descriptors to File | ||||||||||
utimes | Modify file recent access time attributes | ||||||||||
getFormatFileSize | Format file size | ||||||||||
persistPermission persistPermissionEasy | PersistPermissionEasy | PersistPermissionEasy | PersistPermissionEasy | PersistPermissionEasy | PersistPermissionEasy | PersistPermissionEasy | PersistPermissionEasy | PersistPermissionEasy | PersistPermissionEasy | PersistPermissionEasy | PersistPermissionEasy (Permission required: ohos.permission.FILE_ACCESS_PERSIST) |
revokePermission revokePermissionEasy | Unpersistence authorization for multiple selected files or directories uri. (Permission required: ohos.permission.FILE_ACCESS_PERSIST) | ||||||||||
activatedPermission activatePermissionEasy | Enable permissions that have been persisted authorized, otherwise the permissions that have been persisted authorized cannot be used. (Permission required: ohos.permission.FILE_ACCESS_PERSIST) | ||||||||||
deactivatePermission deactivatePermissionEasy | Cancel multiple authorized files or directories. (Permission required: ohos.permission.FILE_ACCESS_PERSIST) | ||||||||||
checkPersistentPermission | Verify the selected multiple file or directory URI persistence authorization. (Permission required: ohos.permission.FILE_ACCESS_PERSIST) |
ImageUtil (image-related tool class)使用案例
Methods | Introduction |
base64ToPixelMap | Picture base64 string to PixelMap |
pixelMapToBase64Str | PixelMap to picture base64 string |
savePixelMap | Save pixelMap to local |
saveImageSource | Save ImageSource to local |
createImageSource | Create image source instance |
createIncrementalSource | Create an image source instance in incremental way |
packingFromPixelMap | Picture compression or repackaging, use Promise to return the result |
packingFromImageSource | Image compression or repackaging, use Promise to return the result |
packToFileFromPixelMap | Encode the PixelMap image source and package it directly into the file |
packToFileFromImageSource | Encode the ImageSource image source and package it directly into the file |
getPixelMapFromMedia | User gets the picture in media under the resource directory PixelMap |
compressedImage | Image compression |
compressPhoto | Picture compression, return to the compressed picture file path |
PreviewUtil (file preview tool class)使用案例
Methods | Introduction |
generatePreviewInfo | Build PreviewInfo from file uri |
openPreview | Open the preview window by passing in file preview information. Repeated calls within 1 second are invalid |
openPreviewEasy | Open the preview window through the uri of the file. Repeated calls within 1 second are invalid |
canPreview | Determine whether the file can be previewed based on the uri of the file |
hasDisplayed | Determine whether the preview window already exists |
closePreview | Close the preview window, only effective if the preview window exists |
loadData | Load preview file information. Only effective if the preview window exists |
loadDataEasy | Load preview file information. Only effective if the preview window exists |
onSharePreview | Call other app preview files |
getTypeDescriptor | Get TypeDescriptor (descriptive class for standardized data types) |
getMimeType | Get file mimeType according to file suffix name |
getIconFileStr | Get the icon of the corresponding file type according to the file suffix name |
LocationUtil (positioning tool class (WGS-84 coordinate system))使用案例
Methods | Introduction |
isLocationEnabled | Determine whether the location service has been enabled (registered is enabled). |
requestLocationPermissions | Apply for positioning permissions |
getCurrentLocationEasy | Get current location |
getCurrentLocation | Get current location |
getLastLocation | Get the last location |
onLocationChangeEasy | Enable location change subscription and initiate positioning request. |
onLocationChange | Enable location change subscription and initiate positioning request |
offLocationChange | Close the location change subscription and delete the corresponding location request |
onLocationError | Error codes during subscription continuous positioning |
offLocationError | Error codes during unsubscribe to continuous positioning |
onLocationEnabledChange | Subscription Location Service Status Change |
offLocationEnabledChange | Unsubscribe to location service status changes |
isGeocoderAvailable | Determine whether geocoding and inverse geocoding services are available |
getAddressFromLocationName | Geocode, convert geographic description to specific coordinates |
getGeoAddressFromLocationName | Geocode, converting geographic description into a specific coordinate set |
getAddressFromLocation | Inverse geocoding, convert coordinates to geographic description |
getGeoAddressFromLocation | Inverse geocoding, convert coordinates to geodescription collection |
getCountryCode | Get the current country code |
calculateDistance | Calculate the straight line distance between these two points in meters |
calculateDistanceEasy | Calculate the straight line distance between these two points based on the specified two latitude and longitude coordinate points, in meters |
convertCoordinate convertCoordinateSync | Coordinate conversion, convert WGS84 coordinate system to GCJ02 coordinate system |
convertCoordinateEasy | Coordinate conversion, convert WGS84 coordinate system to GCJ02 coordinate system |
getErrorMsg | Get positioning related error msg |
LogUtil (log tool class)使用案例
Methods | Introduction |
init | Initialize log parameters (this method is recommended to be called in Ability) |
setDomain | Set the domain identifier corresponding to the log, the range is 0x0~0xFFFF. (This method is recommended to be called in Ability) |
setTag | Set the log identifier (this method is recommended to be called in Ability) |
setShowLog | Whether to print the log (this method is recommended to be called in Ability) |
setHilog | Log printing method (this method is recommended to be called in Ability) |
debug | Print DEBUG level log |
info | Print INFO level log |
warn | Print WARN level log |
error | Print ERROR level log |
fatal | Print FATAL level log |
Print log, no borders. |
CrashUtil (global exception capture, crash log collection)使用案例
Methods | Introduction |
onHandled | Register an error observer (this method is recommended to be called in Ability). After registration, you can capture the js crash generated by the application, and the process will not exit when the application crashes. Write exception information to local file |
onDestroy | Log out the error observer |
isHandled | Determine whether the error observer exists |
getFilePath | Get the log file path (used to read exception files and export exception files) |
access | Determine whether the log file exists |
delete | Delete log file |
getExceptionJson | Get the JSON string for the exception log |
getExceptionList | Get collection of exception logs |
enableAppRecovery | Enable the application recovery function and fill in the parameters in order. After this interface is called, the first Ability supports recovery when the application starts from the initiator. |
restartApp | Restart APP and pull up the first Ability when the application starts. You can use it with the errorManager related interface |
saveAppState | Save the current App status or actively save the state of Ability, which will be used the next time you resume startup. It can be used with errorManager-related interface |
setRestartWant | Set the next time you restore the Ability in the scene actively pulling up. This Ability must be the UIAbility under the current package |
EmitterUtil (Emitter tool class (for inter-thread communication))使用案例
Methods | Introduction |
post | Send Event |
onSubscribe | Subscription Events |
onceSubscribe | Single subscription specified event |
unSubscribe | Unsubscribe |
getListenerCount | Get the number of subscriptions for the specified event |
on | Subscribe to events, support Callback |
once | single subscription to specified events, support Callback |
off | Unsubscribe to event, support Callback |
WantUtil (Want tool class)使用案例
Methods | Introduction |
toSetting | Jump the system settings page (used with the URI constants in WantUtil to jump to more settings pages) |
toAppSetting | Jump to App Settings Page |
toNotificationSetting | Jump notification settings page |
toNetworkSetting | Jump to the mobile network settings page |
toWifiSetting | Jump to WLAN Settings Page |
toBluetoothSetting | Jump Bluetooth Settings Page |
toNfcSetting | Jump NFC Settings Page |
toVolumeSetting | Jump sound and vibration settings page |
toStorageSetting | Jump Storage Settings Page |
toBatterySetting | Jump Battery Settings Page |
toWebBrowser | Pull up the system browser |
toAppGalleryDetail | Pull up the application details interface corresponding to the application market |
toFileManagement | Pull up the system file manager |
startMMS | Pull up the SMS interface and specify the contact person |
openFile | Call three-party software to open the file |
KvUtil (key value database tool class)使用案例
Methods | Introduction | |
put | Add key-value pairs of the specified type to the database | |
get getString getNumber getBoolean getUint8Array | Get the value of the specified key | |
delete | Delete data with specified key value from the database | |
putBatch | Batch insert key-value pairs into SingleKVStore database | |
deleteBatch | Batch delete key-value pairs in SingleKVStore database | |
getEntries | Get all key-value pairs that match the specified key prefix | |
backup | Backup database with a specified name | |
restore | Restore | Recover database from specified database file |
deleteBackup | Delete backup file according to the specified name | |
onDataChange | Subscribe to data change notifications for specified types | |
offDataChange | Unsubscribe to data change notification |
PreferencesUtil (Preferences tool class)使用案例
Methods | Introduction |
init | Initialization |
put putSync | Cache data |
get getSync | Get cached value |
getString getStringSync | Get cached value of string type |
getNumber getNumberSync | Get cached value of type number |
getBoolean getBooleanSync | Get cached value of boolean type |
has hasSync | Check whether the cache instance contains the stored key-value pair for the given key |
getBoolean getBooleanSync | Get cached value of boolean type |
delete deleteSync | Delete cache value |
clear clearSync | Clear cache |
deletePreferences | Remove the specified Preferences instance from the cache. If the Preferences instance has a corresponding persistent file, its persistent file will be deleted at the same time. |
onChange | Subscribe to data change. After the value of the subscribed Key is changed, the callback callback is triggered after the flush method is executed |
offChange | Unsubscribe to data changes |
onDataChange | Accurate subscription data changes. Only after the subscribed key value changes, the callback callback is triggered after the flush method is executed |
offDataChange | Cancel the exact subscription data change |
CacheUtil (cache tool class)使用案例
Methods | Introduction |
has | Whether the cached data exists |
get | Get the cached data |
put | Save data into cache |
remove | Delete the cache corresponding to the key |
isEmpty | Determine whether the cache is empty |
clear | Clear cached data |
LRUCacheUtil (LRUCache Cache Tool Class)使用案例
Methods | Introduction |
getInstance | Get singleton of LRUCacheUtil |
has | Determine whether the cache corresponding to the key is included |
get | Get the cache corresponding to the key |
put | Add cache to lruCache |
remove | Delete the cache corresponding to the key |
isEmpty | Determine whether the lruCache cache is empty |
getCapacity | Get the capacity of the current buffer |
updateCapacity | Reset the capacity of lruCache |
clear | Clear cache data and reset lruCache size |
NotificationUtil (notification tool class)使用案例
Methods | Introduction |
setDefaultConfig | Set the default unified configuration for notifications |
isNotificationEnabled isNotificationEnabledSync | Query whether the notification is authorized |
authorizeNotification | Request notification authorization, and the first call will pop up the window for the user to choose. |
isSupportTemplate | Check whether the template exists, currently only progress bar templates are supported. |
isDistributedEnabled | Query whether the device supports distributed notifications |
publishBasic | Publish normal text notification |
publishMultiLine | Publish multi-text notification |
publishLongText | Publish long text notification |
publishPicture | Publish notifications with pictures |
publishTemplate | Publish Template Notification |
cancel | cancel notice |
cancelGroup | Cancel notifications under the specified group of this application |
cancelAll | Cancel All Notifications |
setBadge | Set the number of desktop angle marks |
clearBadge | Clear the corner marker on the desktop |
setBadgeFromNotificationCount | Set the number of desktop corner markers, from the number of notifications |
getActiveNotificationCount | Get the number of notifications that are not deleted by the current application |
getActiveNotifications | Get the list of notifications that are not deleted by the current application |
addSlot | Create a notification channel of a specified type |
getSlot | Get a notification channel of a specified type |
getSlots | Get all notification channels for this application |
removeSlot | Delete notification channel of the type specified by this application |
removeAllSlots | Delete all notification channels for this application |
generateNotificationId | Generate notification id (using timestamp as id) |
getDefaultWantAgent | Create a Want that pulls up Ability |
getCompressedPicture | Get compressed notification image (the total number of bytes of image pixels cannot exceed 2MB) |
getCompressedIcon | Get the compressed notification icon (the total number of bytes of the icon pixels does not exceed 192KB) |
SnapshotUtil (component screenshot and window screenshot tool class)使用案例
Methods | Introduction |
get getSync | Get screenshots of the loaded component, pass in the component id of the component, find the corresponding component to take screenshots |
createFromBuilder | Render CustomBuilder custom components in the application background and output their screenshots |
snapshot | Get window screenshot, use Promise asynchronous callback |
onSnapshotListener | Turn on monitoring of system screenshot events |
removeSnapshotListener | Close the monitoring of system screenshot events |
KeyboardUtil (keyboard tool class)使用案例
Methods | Introduction |
show | Pull up the keyboard |
hide | Hide keyboard |
onKeyboardListener | Subscribe to input method soft keyboard to show and hide events |
removeKeyboardListener | Unsubscribe to input method soft keyboard to show or hide events |
PasteboardUtil (clipboard tool class)使用案例
Methods | Introduction |
requestPermissions | Apply for clipboard permissions |
getSystemPasteboard | Get System Clipboard Object |
hasData hasDataSync | Determine whether there is any content in the system clipboard |
setData setDataSync | Write data to the system clipboard |
getData getDataSync | Read the system clipboard content |
setDataText setDataTextSync | Write plain text data to the system clipboard |
getDataText getDataTextSync | Read the plain text content of the system clipboard |
setDataHtml setDataHtmlSync | Write HTML data to the system clipboard |
getDataHtml getDataHtmlSync | Read system clipboard HTML content |
setDataUri setDataUriSync | Write URI data to the system clipboard |
getDataUri getDataUriSync | Read the URI content of the system clipboard |
setDataWant setDataWantSync | Write Want data to the system clipboard |
getDataWant getDataWantSync | Read the Want content of the system clipboard |
setDataPixelMap setDataPixelMapSync | Write PixelMap data to the system clipboard |
getDataPixelMap getDataPixelMapSync | Read the system clipboard PixelMap content |
getDataStr getDataStrSync | Read strings in the system clipboard |
getDataEasy | Read content in the system clipboard (plain text content, HTML content, URI content, Want content, PixelMap content) |
clearData clearDataSync | Clear system clipboard content |
AssetUtil (key asset storage service tool class)使用案例
Methods | Introduction |
add addSync | Add a key asset |
get getSync | Query key assets |
remove removeSync | Delete key assets |
canIUse | Whether the current device supports this module |
ResUtil (resource tool class)使用案例
Methods | Introduction |
getResourceManager | Get the ability to provide access to application resources |
getBoolean | Get the boolean result corresponding to the specified resource |
getBooleanByName | Get the boolean result corresponding to the specified resource name |
getNumber | Get the integer value or float value corresponding to the specified resource |
getNumberByName | Get the integer value or float value corresponding to the specified resource name |
getStringValue getStringSync | Get the string corresponding to the specified resource |
getStringByName getStringByNameSync | Get the string corresponding to the specified resource name |
getStringArrayValue getStringArrayValueSync | Get the string array corresponding to the specified resource |
getStringArrayByName getStringArrayByNameSync | Get the string array corresponding to the specified resource name |
getPluralStringValue getPluralStringValueSync | Get a single-plural numeric string represented by the specified resource object based on the specified number |
getPluralStringByName getPluralStringByNameSync | Get a single-plural numeric string represented by the specified resource name based on the specified number |
getColor getColorSync | Get the color value corresponding to the specified resource (decimal) |
getColorByName getColorByNameSync | Get the color value corresponding to the specified resource name (decimal) |
getMediaContent getMediaContentSync | Get the default or specified screen density media file content corresponding to the specified resource |
getMediaByName getMediaByNameSync | Get the default or specified screen density media file content corresponding to the specified resource name |
getMediaContentBase64 getMediaContentBase64Sync | Get the default or specified screen density picture resource Base64 encoding corresponding to the specified resource ID |
getMediaBase64ByName getMediaBase64ByNameSync | Get the default or specified screen density picture resource Base64 encoding corresponding to the specified resource name |
getRawFileContent getRawFileContentSync | Get the content of the corresponding rawfile file in the resources/rawfile directory |
getRawFileContentStr getRawFileContentStrSync | Get the content of the corresponding rawfile file in the resources/rawfile directory (string) |
getRawFileList getRawFileListSync | Get the folder and file list in the resources/rawfile directory (if there is no file in the folder, it will not be returned; if there is a file in the folder, it will return the folder and file list) |
getRawFd | User obtains the descriptor information of the corresponding rawfile file in the resources/rawfile directory |
closeRawFd closeRawFdSync | User closes the descriptor information of the rawfile file in the resources/rawfile directory |
addResource | When the application runs, load the specified resource path to achieve resource coverage |
removeResource | When the user runs, remove the specified resource path and restore the resource before it was overwritten |
isRawDir | The user determines whether the specified path is a directory under rawfile (true: means it is a directory under rawfile, false: means it is not a directory under rawfile) |
getConfiguration getConfigurationSync | Get the device's Configuration |
getDeviceCapability getDeviceCapabilitySync | Get DeviceCapability for DeviceCapability |
ObjectUtil (Object Tool Class)使用案例
Methods | Introduction |
getHash | Get the Hash value of the object |
getClassName | Get the Class name of the object |
getMethodsNames | Get all method names of the object |
isString | Determine whether it is a String |
isNull | Determine whether the object is empty |
isEmpty | Determine whether the attribute content is empty |
shallowCopy | shallowCopy |
deepCopy | Deep Copy Object |
assign | Merge two or more objects |
objToClass | obj to class to solve the problem of missing method after obj as class |
deleteRecord | DeleteElements in Record |
getValue | Get object value through key |
setValue | Dynamically add or modify attributes to object obj |
JSONUtil (JSON tool class)使用案例
Methods | Introduction |
jsonToBean | JSON string to object |
beanToJsonStr | Object to JSON string |
jsonToArray | JSON string to Array |
jsonToMap | JSON string to Map |
mapToJsonStr | Map to JSON string |
isJSONStr | Determine whether it is a string format json |
DateUtil (date tool class)使用案例
Methods | Introduction |
getFormatDate | Get the formatted date and format the incoming date as Date |
getFormatDateStr | Get the formatted date and format the incoming date into a string of the specified format |
getToday | Get today's date |
getTodayTime | Get the timestamp for today |
getTodayStr | Get the time of today, string type |
isToday | Determine whether the date is today |
getNowYear | Get the current year |
getNowMonth | Get the current month |
getNowDay | Get Current Day |
isLeapYear | Determine whether it is a leap year |
getDaysByYear | Get the number of days in the specified year |
getDaysByMonth | Get the number of days in the specified month |
isSameYear | Determine whether two dates are the same year |
isSameMonth | Determine whether two dates are the same month |
isSameWeek | Determine whether two dates are the same week |
isSameDay | Determine whether it is the same day |
isWeekend | Determine whether the specified date is a weekend in the calendar |
compareDays | Compare the number of days when the specified date is different |
compareDate | Compare the number of milliseconds of the specified date |
getAmountDay | Get the date of the previous or the date of the next |
getAmountDayStr | Get the date of the previous few days or the date of the next few days, return the string |
getBeforeDay | Get the previous day date |
getBeforeDayStr | Get the date of the previous day, return the string |
getAfterDay | Day after obtain |
getAfterDayStr | Get the date after the day, return the string |
getWeekOfMonth | Get what week of the month a given date is |
getWeekDay | Get the given date is the day of the week |
getLastDayOfMonth | Get what day the last day of a given year and month |
getFormatTime | Format Time Date String (DateTimeFormat) |
getFormatRange | Format time date field string (DateTimeFormat) |
getFormatRelativeTime | Format Relative Time |
getTipDateStr | Format timestamps to get prompt time strings |
Base64Util (Base64 tool class)使用案例
Methods | Introduction |
decode encodeSync | Decode, decode through input parameters and output corresponding Uint8Array object |
encode decodeSync | Encoding, output Uint8Array object after inputting parameters |
encodeToStr encodeToStrSync | Encode, output the corresponding text after inputting parameters |
StrUtil (String tool class)使用案例
Methods | Introduction | |
isNull | Determine whether the string is empty (undefined, null) | |
isNotNull | Determine whether the string is non-empty | |
isEmpty | Determine whether the string is empty (undefined, null, string length is 0) | |
isNotEmpty | Determine whether the string is non-empty | |
isBlank | Determine whether the string is empty and whitespace (whitespace includes spaces, tabs, full-width spaces and uninterrupted spaces) | |
isNotBlank | Determine whether the string is non-empty | |
trim | Remove spaces at both ends of strings | |
trimAll | Remove all spaces in string | |
replace | replace the matching regular in the string to the given string | |
replaceAll | ReplaceAll | Replace all matching regulars in the string to the given string |
startsWith | Determine whether a string starts with the given string | |
endsWith | Determine whether a string ends in the given string | |
repeat | repeat string number | |
toLower | Convert the entire string to lowercase | |
toUpper | Convert the entire string to uppercase | |
capitalize | Convert the first letter of the string to uppercase, and the rest to lowercase | |
equal | Determine whether two incoming values or strings are equal | |
notEqual | Determine whether two incoming values or strings are not equal | |
strToUint8Array | String to Uint8Array | |
unit8ArrayToStr | Uint8Array to string | |
strToBase64 | String to Base64 string | |
base64ToStr | Base64 string to string | |
strToBuffer | String to ArrayBuffer | |
bufferToStr | ArrayBuffer to string | |
bufferToUint8Array | ArrayBuffer to Uint8Array | |
unit8ArrayToBuffer | Uint8Array to ArrayBuffer | |
getErrorStr | Get the JSON string of Error | |
getErrnoToString | Get detailed information corresponding to the system error code |
CharUtil (character tool class)使用案例
Methods | Introduction |
isDigit | Determine whether the string char is a number |
isLetter | Determine whether the string char is a letter |
isLowerCase | Determine whether the string char is a lowercase letter |
isUpperCase | Determine whether the string char is capital letter |
isSpaceChar | Determine whether the string char is a space character |
isWhitespace | Determine whether the string char is a whitespace |
isRTL | Determine whether the string char is a character from right to left language |
isIdeograph | Determine whether the string char is an ideographic text |
isBlankChar | Determine whether there is a blank symbol. White space symbols include spaces, tab characters, full-width spaces and uninterrupted spaces |
isAscii | Determine whether the character is within the ASCII range (0~127) |
NumberUtil (number tool class)使用案例
Methods | Introduction |
isNaN | Check if the value is NaN |
isFinite | Check if the value is a finite number |
isInteger | Check if the value is an integer |
isSafeInteger | Check if the value is a safe integer |
isNumber | Determine whether it is a numerical value |
isEven | Check if the number is even |
isOdd | Check if the number is odd |
toNumber | Convert string to Number |
toInt | Convert string to integer |
toFloat | Convert string to floating point |
average | Calculate the average of the numbers |
add | Add |
sub | subtraction |
sum | sum |
toDecimal | Construct Decimal |
addDecimal | Addition Decimal |
subDecimal | Subtraction Decimal |
sumDecimal | SumDecimal |
ArrayUtil (collection tool class)使用案例
Methods | Introduction |
isNotEmpty | Determine whether a collection is a non-empty collection |
isEmpty | Determine whether a set is an empty set |
removeEmpty | Remove empty values from string array |
trim | Removes the spaces before and after each value of the string array |
distinct | Deduplicate the array, and after deduplicate it, generate a new array, the original array remains unchanged |
reverse | Inverting the array will modify the original array |
filter | Array filtering, filtering and returning required elements through filter function implementation |
append | Splice data, use extension operators, and do not affect the original array. |
min | Get the minimum value of the array (value, string, date) |
max | Get the maximum value of the array (value, string, date) |
flatten | tiled 2D array |
union | Tile a 2D array and deduplicate |
chunk | Array chunking |
contains | Determine whether the set contains a certain value |
remove | Remove a value from the collection |
RandomUtil (random tool class)使用案例
Methods | Introduction |
getRandomBoolean | Generate random Boolean values |
getRandomInt | Generate random integers (the range can be specified) |
getRandomNumber | Generate random numbers in a specified range |
getRandomLimit | Generate random numbers in the specified range [0,limit) |
getRandomChineseChar | Generate a random Chinese character |
getRandomChinese | Generate random Chinese characters |
getRandomStr | Randomgenerates strings of specified length based on the specified string |
getRandomDataBlob | Generate DataBlob of randomly specified length |
getRandomUint8Array | Generate Uint8Array of randomly specified length |
getRandomColor | Generate random colors, hexadecimal |
generateUUID36 | Generate 36-bit UUID with - |
generateUUID32 | Generate 32-bit UUID with - |
generateRandomUUID | Generate a random RFC 4122 version 4 string type UUID using Encrypted Secure Random Number Generator |
generateRandomBinaryUUID | Generate Random RFC 4122 Version 4 Uint8Array Type UUID using Encrypted Secure Random Number Generator |
RegexUtil (regular tool class)使用案例
Methods | Introduction |
isMatch | Whether the given content matches the regular (used with regular constants in RegexUtil) |
isPhone | Determine whether the incoming phone number is formatted correctly |
isDigits | Check if the string contains only numeric characters |
isEmail | Determine whether the incoming email is formatted correctly |
isEmoji | Determine whether a string contains emoticons |
isValidCard | Verify the validity of ID number |
TypeUtil (Type Checking Tool Class)使用案例
Methods | Introduction |
isBoolean | Determine whether it is Boolean type |
isNumber | Determine whether it is Number type |
isString | Determine whether it is String type |
isObject | Determine whether it is Object type |
isArray | Determine whether it is an array type |
isResource | Determine whether it is Resource type |
isResourceStr | Determine whether it is ResourceStr type |
isFunction | Determine whether it is a function type |
isMap | Check if it is Map type |
isWeakMap | Check if it is WeakMap type |
isSet | Check whether it is Set type |
isWeakSet | Check if it is WeakSet type |
isDate | Check if it is Date type |
isArrayBuffer | Check whether it is ArrayBuffer type |
isSharedArrayBuffer | Check if it is SharedArrayBuffer type |
isAnyArrayBuffer | Check if it is ArrayBuffer or SharedArrayBuffer type |
isUint8Array | Check if it is a Uint8Array array type |
isUint16Array | Check if it is a Uint16Array array type |
isUint32Array | Check if it is a Uint32Array array type |
isInt8Array | Check if it is an Int8Array array type |
isInt16Array | Check if it is an Int16Array array type |
isInt32Array | Check if it is an Int32Array array type |
isTypedArray | Check if it is TypedArray |
isAsyncFunction | Check if it is an asynchronous function type |
isPromise | Check if it is a Promise type |
isProxy | Check if it is Proxy type |
isRegExp | Check if it is RegExp type |
isDataView | Check if it is DataView type |
isExternal | Check if it is native External type |
isNativeError | Check if it is Error type |
FormatUtil (format tool class)使用案例
Methods | Introduction |
isPhone | Determine whether the incoming phone number is formatted correctly |
getPhoneFormat | Format phone numbers |
getPhoneLocationName | Get phone number home |
transliterator | Convert input string from source format to target format (convert Chinese characters to pinyin) |
getFormatPercentage | Format percentage to convert numbers from percentage string |
getFormatPhone | Format mobile phone number, hide the four middle digits |
getFormatCardNo | Format ID number, hide the middle part number |
getFormatFileSize | Format file size |
getTruncateText | Shorten the long text, the excess is represented by an ellipsis |
getIconFont | parse iconFont characters |
getQueryValue | Get the parameters in the url, the value corresponding to the Key |
getParamsUrl | Splice parameters on the url and return the new url |
ClickUtil (throttling, anti-shake tool category)使用案例
Methods | Introduction |
throttle | Throttle: Only trigger once within a certain period of time |
debounce | Anti-shake: within a certain period of time, only the last operation will be executed, and the function will be executed after waiting milliseconds |
TempUtil (temperature conversion tool class)使用案例
Methods | Introduction |
C2F | degrees Celsius to degrees Fahrenheit |
F2C | Fahrenheit to Celsius |
C2K | Celsius to Kelvin |
K2C | Kelvin to Celsius |
F2K | Fahrenheit to Kelvin |
K2F | Kelvin to Fahrenheit |
DialogUtil (pop-up tool class)使用案例
Methods | Introduction |
setDefaultConfig | Set default uniform style |
showConfirmDialog | Show pop-up window (a button) |
showPrimaryDialog | Show pop-up window (two buttons) |
showDialog | Display pop-up window (multiple buttons) |
showActionSheet | List selection pop-up |
showCalendarPicker | Calendar Selector Popup |
showDatePicker | Date Sliding Selector Popup |
showTimePicker | Time Sliding Selector Popup |
showTextPicker | Text Sliding Selector Popup |
ToastUtil (toast tool class)使用案例
Methods | Introduction |
setDefaultConfig | Set default uniform style |
showToast | Pop up toast, default duration is 2s |
showShort | Pop up short toast, default duration is: 1.5s |
showLong | Pop up long toast, default duration is: 10s |
SM2 (SM2 encryption and decryption)使用案例
Methods | Introduction |
encrypt encryptSync | Encrypt |
decrypt decryptSync | Decrypt |
generateKeyPair generateKeyPairSync | GenerateKeyPairKeyPair |
getConvertKeyPair getConvertKeyPairSync | Get the converted asymmetric key KeyPair |
getSM2PubKey | Get the convert SM2 public key, convert the SM2 public key in C1C2C3 format to the ASN.1 format required by Hongmeng |
getSM2PriKey | Get Convert SM2 Private Key |
getCipherTextSpec | Get convert SM2 ciphertext format, ASN.1 format to C1C2C3 or C1C3C2 |
sign signSync | Sign data |
verify verifySync | Verify the data |
signSegment signSegmentSync | SegmentSync |
verifySegment verifySegmentSync | Perform segment verification of data |
SM3 (SM3 tool class)使用案例
Methods | Introduction |
digest digestSync | SM3 Summary |
digestSegment digestSegmentSync | SM3 segment summary |
hmac hmacSync | SM3 message authentication code calculation |
hmacSegment hmacSegmentSync | SM3 message authentication code calculation, segmentation |
SM4 (SM4 encryption and decryption)使用案例
Methods | Introduction |
encrypt encryptSync | Encrypt |
decrypt decryptSync | Decrypt |
encryptGCM encryptGCMSync | Encrypt (GCM mode) |
decryptGCM decryptGCMSync | Decrypt (GCM mode) |
encryptCBC encryptCBCSync | Encrypt (CBC mode) |
decryptCBC decryptCBCSync | Decrypt (CBC mode) |
encryptECB encryptECBSync | Encrypt (ECB mode) |
decryptECB decryptECBSync | Decrypt (ECB mode) |
encryptGCMSegment encryptGCMSegmentSync | Encrypt (GCM mode) segmentation |
decryptGCMSegment decryptGCMSegmentSync | Decrypt (GCM mode) segmentation |
generateSymKey generateSymKeySync | Generate SymKey |
AES (AES encryption and decryption)使用案例
Methods | Introduction |
encrypt encryptSync | Encrypt |
decrypt decryptSync | Decrypt |
encryptGCM encryptGCMSync | Encrypt (GCM mode) |
decryptGCM decryptGCMSync | Decrypt (GCM mode) |
encryptCBC encryptCBCSync | Encrypt (CBC mode) |
decryptCBC decryptCBCSync | Decrypt (CBC mode) |
encryptECB encryptECBSync | Encrypt (ECB mode) |
decryptECB decryptECBSync | Decrypt (ECB mode) |
encryptGCMSegment encryptGCMSegmentSync | Encrypt (GCM mode) segmentation |
decryptGCMSegment decryptGCMSegmentSync | Decrypt (GCM mode) segmentation |
generateSymKey generateSymKeySync | Generate SymKey |
DES (DES encryption and decryption)使用案例
Methods | Introduction |
encrypt encryptSync | Encrypt |
decrypt decryptSync | Decrypt |
encryptECB encryptECBSync | Encrypt (ECB mode) |
decryptECB decryptECBSync | Decrypt (ECB mode) |
encryptCBC encryptCBCSync | Encrypt (CBC mode) |
decryptCBC decryptCBCSync | Decrypt (CBC mode) |
generateSymKey generateSymKeySync | Generate SymKey |
RSA (RSA encryption and decryption)使用案例
Methods | Introduction |
encrypt encryptSync | Encrypt |
decrypt decryptSync | Decrypt |
encryptSegment encryptSegmentSync | Encrypt, segmentation |
decryptSegment decryptSegmentSync | Decrypt, segmentation |
generateKeyPair generateKeyPairSync | GenerateKeyPairKeyPair |
getConvertKeyPair getConvertKeyPairSync | Get the converted asymmetric key KeyPair |
sign signSync | Sign data |
verify verifySync | Verify the data |
signSegment signSegmentSync | SegmentSync |
verifySegment verifySegmentSync | Perform segment verification of data |
recover recoverSync | Sign the data and restore the original data, currently only RSA supports |
MD5 (MD5 tool class)使用案例
Methods | Introduction |
digest digestSync | MD5 Summary |
digestSegment digestSegmentSync | MD5 abstract, segmentation |
hmac hmacSync | Message authentication code calculation |
hmacSegment hmacSegmentSync | Message authentication code calculation, segmentation |
SHA (SHA tool class)使用案例
Methods | Introduction |
digest digestSync | SHA Summary |
digestSegment digestSegmentSync | SHA abstract, segmentation |
hmac hmacSync | Message authentication code calculation |
hmacSegment hmacSegmentSync | Message authentication code calculation, segmentation |
ECDSA (ECDSA tool class)使用案例
Methods | Introduction |
sign signSync | Sign data |
verify verifySync | Verify the data |
signSegment signSegmentSync | SegmentSync |
verifySegment verifySegmentSync | Perform segment verification of data |
CryptoUtil (encryption and decryption utility class, used with each encryption module)
Methods | Introduction |
encrypt encryptSync | Encrypt |
decrypt decryptSync | Decrypt |
generateSymKey generateSymKeySync | Generate SymKey |
getConvertSymKey getConvertSymKeySync | Get the converted symmetric key SymKey |
generateKeyPair generateKeyPairSync | GenerateKeyPairKeyPair |
getConvertKeyPair getConvertKeyPairSync | Get the converted asymmetric key KeyPair |
getPemKeyPair | Get the specified data to generate an asymmetric key |
generateIvParamsSpec | Generate IvParamsSpec |
getIvParamsSpec | Get Convert IvParamsSpec |
generateGcmParamsSpec | GenerateGcmParamsSpec |
getGcmParamsSpec | Get Convert GcmParamsSpec |
sign signSync | Sign data |
verify verifySync | Verify the data |
signSegment signSegmentSync | SegmentSync |
verifySegment verifySegmentSync | Perform segment verification of data |
dynamicKey dynamicKeySync | Key Negotiation |
digest digestSync | Abstract |
digestSegment digestSegmentSync | Abstract, segmentation |
hmac hmacSync | Message authentication code calculation |
hmacSegment hmacSegmentSync | Message authentication code calculation, segmentation |
CryptoHelper (encrypted and decrypted data type conversion, used with each encryption module)
Methods | Introduction |
strToDataBlob | String to DataBlob |
dataBlobToStr | DataBlob to String |
strToUint8Array | String to Uint8Array |
uint8ArrayToStr | Uint8Array to String |
getSymKeyDataBlob | Get the key of type DataBlob |
getKeyDataBlob | Get the public or private key of type DataBlob |
getRandomUint8Array | Generate random Uint8Array based on the incoming size |
getUint8ArrayPaddingZero | Uint8Array Zero Operation |
toHexWithPaddingZero | Zero Compensation Operation |
stringToHex | string to Hex string |
uint8ArrayToString | Bytes to Understandable String |
PickerUtil (photographing, file selection and saving, tool class)拆分至 picker_utils
Methods | Introduction |
camera cameraEasy | Call the system camera, take photos, record videos |
selectPhoto | Pull up the photoPicker interface by selecting mode, users can select one or more pictures/videos |
savePhoto | Pull up photoPicker in the save mode to save the file name of the picture or video resource. If there are no parameters, the user needs to enter it by default |
selectDocument | Pull up the documentPicker interface by selecting mode, users can select one or more files |
saveDocument | Pull up the documentPicker interface through the save mode, and users can save one or more files |
selectAudio | Pull up the audioPicker interface by selecting mode, users can select one or more audio files |
saveAudio | Pull up the audioPicker interface through save mode, and users can save one or more audio files |
PhotoHelper (album related, tool category)拆分至 picker_utils
Methods | Introduction |
select selectEasy | Pull up the photoPicker interface by selecting mode, users can select one or more pictures/videos |
save | Apply for permission to save pictures or videos to the album. |
showAssetsCreationDialog | Pop-up window authorization save, call the interface to pull up the save confirmation pop-up window. |
showAssetsCreationDialogEasy | Pop-up window authorization save, call the interface to pull up the save confirmation pop-up window, and save. |
applyChanges | Save security controls, submit media change requests, insert pictures/videos. |
getPhotoAsset | Get the PhotoAsset object of the corresponding uri, used to read file information |
ScanUtil (code tool class (scan code, code image generation, picture identification))拆分至 picker_utils
Methods | Introduction |
startScanForResult | Call the default interface to scan the code and use the Promise method to asynchronously return the decoding result |
generateBarcode | Code diagram generation, use Promise to return the generated code diagram asynchronously |
decode | Call picture identification and use Promise to return the identification result asynchronously |
decodeImage | Call image data identification capability, use Promise asynchronous callback to return code identification results |
onPickerScanForResult | Pull up the gallery through picker and select the picture, and call the picture identification code |
canIUseScan | Determine whether the current device supports code capabilities |
🍎Contribution code and technology communication
Any problems found during use can be askedIssueGive us; Of course, we also welcome you to send us a messagePR 。
https://gitee.com/tongyuyan/harmony-utils
https://github.com/787107497
🌏Open Source Protocol
This project is based onApache License 2.0, when copying and borrowing codes, please be sure to indicate the source.
Subscribe to my newsletter
Read articles from 桃花镇童长老 directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
