chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

HarmonyOS開發(fā)實例:【任務(wù)延時調(diào)度】

jf_46214456 ? 來源:jf_46214456 ? 作者:jf_46214456 ? 2024-04-15 09:26 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

介紹

本示例使用[@ohos.WorkSchedulerExtensionAbility] 、[@ohos.net.http]、[@ohos.notification] 、[@ohos.bundle]、[@ohos.fileio] 等接口,實現(xiàn)了設(shè)置后臺任務(wù)、下載更新包 、保存更新包、發(fā)送通知 、安裝更新包實現(xiàn)升級的功能。

效果預(yù)覽

image.png

使用說明

  1. 安裝本應(yīng)用之前,先編譯好未簽名的應(yīng)用包,然后在終端執(zhí)行工程里的腳本,目錄為:WorkScheduler/signTool/b_sign_hap_release.bat;
  2. 未連接wifi狀態(tài)下進入應(yīng)用;
  3. 進入首頁后連接wifi;
  4. 后臺判斷版本號后會下載新的升級包,并在頁面中給出彈窗詢問是否安裝,點擊“確定”按鈕;
  5. 應(yīng)用會安裝已經(jīng)下載的升級包,實現(xiàn)版本更新,安裝后會回到設(shè)備桌面,此時點擊應(yīng)用圖標(biāo),可以看到版本已經(jīng)是新版本了。
  6. 運行自動化測試用例時,必須使用命令行裝包,不能使用ide自動裝包,安裝自動化測試包之前,先編譯好未簽名的測試包, 然后在終端執(zhí)行工程里的腳本,目錄為:WorkScheduler/signTool/a_sign_hap_release.bat;
  7. 運行自動化測試應(yīng)用時需要使用如下命令:
hdc shell aa test -b ohos.samples.workschedulerextensionability -m entry_test -s unittest OpenHarmonyTestRunner -s class ActsAbilityTest -s timeout 150000

代碼解讀

entry/src/main/ets/
|---Application
|   |---MyAbilityStage.ets                  // 入口文件
|---feature
|   |---WorkSchedulerSystem.ets             // 封裝各個功能接口
|---MainAbility
|   |---MainAbility.ets                     // 請求權(quán)限
|---pages
|   |---Index.ets                           // 首頁
|---util
|   |---Logger.ets                          // 日志文件
|---WorkSchedulerAbility
|   |---WorkSchedulerAbility.ets            // 延時任務(wù)觸發(fā)后的回調(diào)
鴻蒙HarmonyOS與OpenHarmony技術(shù)
+mau123789是v直接拿取

搜狗高速瀏覽器截圖20240326151547.png

具體實現(xiàn)

鴻蒙next開發(fā)知識更新在:[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]

  • 設(shè)置延時任務(wù)、下載更新包、保存更新包、發(fā)送通知、安裝更新包的功能接口都封裝在WorkSchedulerSystem中, 源碼參考:[WorkSchedulerSystem.ets]
/*

 * Copyright (c) 2023-2024 Huawei Device Co., Ltd.

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */



import fs from '@ohos.file.fs';

import notificationManager from '@ohos.notificationManager';

import Notification from '@ohos.notification';

import bundle from '@ohos.bundle.installer';

import account from '@ohos.account.osAccount';

import workScheduler from '@ohos.resourceschedule.workScheduler';

import http from '@ohos.net.http';

import { Logger } from '../utils/Logger';



const FILE_NAME = '/UpdateWorkScheduler.hap';

const BUNDLE_NAMES = ['ohos.samples.workschedulerextensionability'];

const INSTALL_PARAMETER = 1;



export namespace WorkSchedulerSystem {

  /**

   * Store the file to the specified directory.

   *

   * @param pathDir Path to save the file.

   * @param content The contents of the file to be saved.

   */

  export function saveFile(pathDir: string, content: ArrayBuffer): void {

    try {

      let filePath = pathDir + FILE_NAME;

      let fd = fs.openSync(filePath, 0o2 | 0o100).fd;

      fs.writeSync(fd, content);

      fs.closeSync(fd);

    } catch (err) {

      Logger.error(`saveFile failed, code is ${err.code}, message is ${err.message}`);

    }

  }



  /**

   * Sending a Notification.

   *

   * @param bundleName Check the name of the application that has permission.

   * @permission ohos.permission.NOTIFICATION_CONTROLLER

   */

  export async function handleNotification(bundleName: string): Promise< void > {

    await notificationManager.requestEnableNotification();

    Notification.subscribe({

      onConsume: (data) = > {

        if (data.request.content.normal.text === 'isReady') {

          AppStorage.SetOrCreate('isShowDialog', true);

        }

      }

    }, {

      bundleNames: BUNDLE_NAMES

    })

  }



  /**

   * Publishes a notification of the specified content.

   *

   * @param title Title of Notice.

   * @param text Content of Notification Text.

   * @param additionalText Additional text.

   * @permission ohos.permission.NOTIFICATION_CONTROLLER

   */

  export function publishNotification(title: string, text: string, additionalText: string): void {

    notificationManager.publish({

      content: {

        contentType: Notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,

        normal: {

          title,

          text,

          additionalText

        }

      }

    })

  }



  /**

   * Install the application package in the specified path.

   *

   * @param filePath An array of paths to hold the installation package.

   * @permission ohos.permission.INSTALL_BUNDLE

   */

  export async function installBundle(filePath: Array< string >): Promise< void > {

    try {

      let bundleInstall = await bundle.getBundleInstaller();

      let userId = await account.getAccountManager().getOsAccountLocalIdFromProcess();

      bundleInstall.install(filePath, {

        userId: userId,

        installFlag: INSTALL_PARAMETER,

        isKeepData: false

      }, (status, statusMessage) = > {

        Logger.info(`installBundle filepath is ${filePath}`);

        Logger.info(`installBundle code is ${status.code}, message is ${JSON.stringify(statusMessage)}`);

      })

    } catch (err) {

      Logger.error(`installBundle failed, code is ${err.code}, message is ${err.message}`);

    }

  }



  /**

   * Register the delayed task and pass the parameters.

   *

   * @param version Current application version.

   * @param bundleName The name of the application package for which the task needs to be registered.

   * @param filePath Storage address of the application package.

   */

  export async function startUpdateSample(version: string, bundleName: string, filePath: string): Promise< void > {

    try {

      let workInfo = {

        workId: 1,

        bundleName: bundleName,

        abilityName: 'WorkSchedulerAbility',

        networkType: workScheduler.NetworkType.NETWORK_TYPE_WIFI,

        parameters: {

          version: version,

          filePath: filePath

        }

      };

      workScheduler.startWork(workInfo);

    }

    catch (err) {

      Logger.error(`startWork failed, code is ${err.code}, message is ${err.message}`);

    }

  }



  /**

   * Register the delayed task and pass the parameters.

   *

   * @param url Url of the application package.

   * @permission ohos.permission.INTERNET

   */

  export async function getNewHap(url: string): Promise< http.HttpResponse > {

    try {

      return await http.createHttp().request(

        url,

        {

          expectDataType: http.HttpDataType.ARRAY_BUFFER

        });

    } catch (err) {

      Logger.error(`get result failed, code is ${err.code}, message is ${err.message}`);

    }

  }

}
  • 設(shè)置延時任務(wù):在運行示例時會在[MainAbility.ets] 通過WorkSchedulerSystem.startUpdateSample()方法調(diào)用workScheduler.startWork()建立任務(wù);
  • 下載更新包:當(dāng)任務(wù)條件滿足后,會在[WorkSchedulerAbility.ets]通過WorkSchedulerSystem.getNewHap()方法調(diào)用http.createHttp().request()接口下載需要的文件;
  • 保存更新包:通過WorkSchedulerSystem.saveFile()來實現(xiàn),受限調(diào)用fileio.openSync()創(chuàng)建文件,然后調(diào)用fileio.writeSync()將下載的內(nèi)容寫入指定文件內(nèi);
  • 發(fā)送通知:在[WorkSchedulerAbility.ets] 中通過WorkSchedulerSystem.publishNotification()方法,調(diào)用Notification.publish()接口發(fā)送指定內(nèi)容的信息;
  • 接收通知:在[MainAbility.ets]中通過WorkSchedulerSystem.handleNotification()方法調(diào)用Notification.subscribe()接口獲取信息,根據(jù)信息內(nèi)容決定是否提示用戶升級;
  • 安裝更新包:在[WorkSchedulerAbility.ets] 通過WorkSchedulerSystem.installBundle()方法實現(xiàn),首先調(diào)用bundle.getBundleInstaller()獲取Installer對象,然后調(diào)用bundleInstall.install()接口實現(xiàn)裝包,完成升級。

審核編輯 黃宇

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • WIFI
    +關(guān)注

    關(guān)注

    82

    文章

    5493

    瀏覽量

    212799
  • 鴻蒙
    +關(guān)注

    關(guān)注

    60

    文章

    2923

    瀏覽量

    45568
  • HarmonyOS
    +關(guān)注

    關(guān)注

    80

    文章

    2151

    瀏覽量

    35847
  • OpenHarmony
    +關(guān)注

    關(guān)注

    33

    文章

    3941

    瀏覽量

    20914
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關(guān)推薦
    熱點推薦

    freertos關(guān)閉任務(wù)調(diào)度的方法

    #include \"FreeRTOS.h\" #include \"task.h\" /* 關(guān)閉任務(wù)調(diào)度 */ void
    發(fā)表于 11-17 06:47

    如何利用UCOS引發(fā)任務(wù)調(diào)度?

    我看資料中的任務(wù)調(diào)度往往發(fā)生在程序延時中,程序釋放CPU引發(fā)任務(wù)調(diào)度,但是我希望程序能夠更快的運行,不想使用
    發(fā)表于 10-24 04:36

    有些UCOSii任務(wù)里面為什么能使用GUI_Delay為任務(wù)調(diào)度延時?

    為什么在有些UCOSii任務(wù)里面可以使用GUI_Delay為任務(wù)調(diào)度延時?
    發(fā)表于 03-20 03:42

    UCOSiii任務(wù)延時時間達(dá)到問題

    之前一個帖子發(fā)錯版塊了當(dāng)延時時間到了后,時鐘節(jié)拍任務(wù)會把該等待延時任務(wù)放入任務(wù)就緒表中,在尋找最高優(yōu)先級的函數(shù)中會找到優(yōu)先級最高的就緒
    發(fā)表于 04-06 04:36

    UCOSIII延時函數(shù)任務(wù)怎么調(diào)度?

    OSTimeDlyHMSM(0,0,0,10,OS_OPT_TIME_PERIODIC,&err);延時10ms。對于這樣的延時函數(shù),會觸發(fā)任務(wù)調(diào)度。我的問題是
    發(fā)表于 04-10 04:36

    UCOSIII延時任務(wù)調(diào)度怎么實現(xiàn)?

    STM32用UCOSIII去寫程序,現(xiàn)在需要延時,但不能進行調(diào)度,延時的時間是幾百毫秒,改怎么搞?
    發(fā)表于 04-17 03:07

    UCOSIII任務(wù)中使用延時函數(shù)進行調(diào)度怎么設(shè)置?

    請教各位大神關(guān)于UCOSIII任務(wù)中使用延時函數(shù)進行調(diào)度的問題:假如我有4個串口中斷,都是每隔500ms使用任務(wù)內(nèi)建消息隊列的OSTaskQPost向處理
    發(fā)表于 05-11 03:07

    FreeRTOS如何使用delay作為系統(tǒng)延時、任務(wù)調(diào)度

    請教一個問題,最近在學(xué)習(xí)使用FreeRTOS,想像原子一樣在delay.c里添加RTOS的系統(tǒng)支持,即使用tick時鐘作延時。現(xiàn)在有幾個問題:1、在啟動任務(wù)調(diào)度器前,如果調(diào)用了delay_ms
    發(fā)表于 06-10 04:37

    請問delay_xms()延時,會不會引起任務(wù)調(diào)度?

    delay_xms()延時,不會引起任務(wù)調(diào)度的意思應(yīng)該是:這個函數(shù)不會主動引起任務(wù)調(diào)度,但是在延時
    發(fā)表于 06-17 04:36

    HarmonyOS應(yīng)用開發(fā)-分布式任務(wù)調(diào)度

    ,體驗HarmonyOS的分布式任務(wù)調(diào)度。您將建立什么在這個CodeLab中,你將創(chuàng)建DemoProject,并將Demo編譯成HAP,此示例應(yīng)用程序展示了如何使用分布式任務(wù)
    發(fā)表于 09-18 09:21

    最遲預(yù)分配容錯實時調(diào)度算法設(shè)計與分析

    提出一種多類型任務(wù)集的容錯實時調(diào)度算法,詳細(xì)分析該算法的調(diào)度機制,證明了該算法的正確性,并給出了該算法的可調(diào)度條件,最后通過模擬實驗分析了算法的性能。實驗表
    發(fā)表于 11-20 12:01 ?17次下載

    基于CANoe總線系統(tǒng)實時調(diào)度的仿真

    基于CANoe總線系統(tǒng)實時調(diào)度的仿真
    發(fā)表于 01-24 17:21 ?22次下載

    任務(wù)閾值調(diào)度算法

    針對當(dāng)前云任務(wù)調(diào)度算法在密碼云環(huán)境中無法實現(xiàn)任務(wù)實時處理的問題,提出一種基于滾動優(yōu)化窗口的實時閾值調(diào)度方法。首先,將密鑰調(diào)用環(huán)節(jié)融入密碼任務(wù)
    發(fā)表于 11-24 17:08 ?5次下載
    云<b class='flag-5'>任務(wù)</b>閾值<b class='flag-5'>調(diào)度</b>算法

    移動終端最優(yōu)節(jié)能任務(wù)調(diào)度

    約束條件下調(diào)度的規(guī)律性,提出按最近截止時間進行分組調(diào)度算法,每組調(diào)度采用動態(tài)最優(yōu)化策略進行決策。實驗結(jié)果表明,該算法在任務(wù)調(diào)度的情況下能夠
    發(fā)表于 02-07 16:30 ?1次下載

    鴻蒙OS 分布式任務(wù)調(diào)度

    鴻蒙OS 分布式任務(wù)調(diào)度概述 在 HarmonyO S中,分布式任務(wù)調(diào)度平臺對搭載 HarmonyOS 的多設(shè)備構(gòu)筑的“超級虛擬終端”提供統(tǒng)
    的頭像 發(fā)表于 01-29 16:50 ?1378次閱讀