# CardInfoRefresh **Repository Path**: hu-min2021/CardInfoRefresh ## Basic Information - **Project Name**: CardInfoRefresh - **Description**: 本示例实现使用router、call和message三种事件,以及定点刷新的方式实现卡片信息的刷新。 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 18 - **Created**: 2024-11-11 - **Last Updated**: 2024-11-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Widget Update ### Overview The first card in this example uses three events: router, call, and message, as well as a fixed-point refresh method to refresh card information. The second card implements the functions of timed refresh of cards and application triggered refresh of cards. ### Preview | First Card | Second Card | |-------------------------------------|--------------------------------------------| | ![](screenshots/device/form.en.png) | ![](screenshots/device/form_second.en.png) | ### Project Directory ``` ├──entry/src/main/ets // Core code │ ├──common │ │ ├──CommonConstants.ets // Widget data │ │ └──CommonData.ets // Utility class for widget data │ ├──entryability │ │ └──EntryAbility.ets // Entry ability │ ├──entrybackupability │ │ └──EntryBackupAbility.ets │ ├──entryformability │ │ └──EntryFormAbility.ets // Widget lifecycle class │ ├──pages │ │ ├──Index.ets // Home page │ └──widget │ ├──pages │ │ └──WidgetCard.ets // Widget page │ ├──view │ │ └──CardListComponent.ets │ └──viewmodel │ └──CardListParameter.ets └──entry/src/main/resources // Static resources ``` ### How to Use **First Card** 1. Install the sample app, and touch and hold the app icon to add a widget. 2. Touch the router event button to go to the app page. When you return to the home screen, you can see that the widget information is updated. 3. Touch the call event. The widget information is updated. 4. Touch the message event. The widget information is updated. 5. Set the **scheduledUpdateTime** field in the **src/main/resources/base/profile/form_config.json** file to a time point. The widget information is updated at the specified time point. **Second Card** 1. After installing the application, the homepage of the application displays a slideshow of images, and the heart-shaped image in the bottom right corner supports clicking. 2. Long press the application image to select create a second card, click on the card to pull up the application. 3. Select the image and click the heart-shaped button to return to the desktop. The image and heart-shaped status information will be updated to the card. 4. Configure the **updateDuration** field in the **src/main/resources/base/profile/form_config.json** file. The update cycle unit for card scheduled refresh is 30 minutes. The example configuration is set to 1, which means that after any update of the card, it will be refreshed at a scheduled time after 30 minutes. ### How to Implement 1. The router event calls the **updateForm** method of **formProvider** in the lifecycle callback of the EntryAbility to update the widget information. 2. The call event updates the widget information in the **onAddForm** method of the EntryFormAbility and triggers the **onFormTimeChange** method of the widget UI. The **updateCardInfo** information carried in the **postCardAction** method is used to trigger the callee listening in the EntryAbility, thereby updating the widget information in the listening method. 3. The message event updates the widget information in the **onFormEvent** callback of the EntryFormAbility. 4. After creating the second card, use the call event to pass the card ID to the Entry Ability and save it to the preferences. The application side retrieves the card ID from the preferences and updates the specified card using the updateForm method. #### NOTE 1. The widget information in this project uses the data configured in the code. In actual scenarios, you can encapsulate a method to obtain the information. ### Required Permissions **ohos.permission.KEEP_BACKGROUND_RUNNING**: allows a ServiceAbility to keep running in the background. The provider app must have the permission to run the call event in the background. ### Constraints 1. The sample app is supported only on Huawei phones running the standard system. 2. The HarmonyOS version must be HarmonyOS NEXT Release or later. 3. The DevEco Studio version must be DevEco Studio NEXT Release or later. 4. The HarmonyOS SDK version must be HarmonyOS NEXT Release or later.