女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

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

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

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

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

jf_46214456 ? 來源:jf_46214456 ? 作者:jf_46214456 ? 2024-04-15 09:26 ? 次閱讀

介紹

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

效果預(yù)覽

image.png

使用說明

  1. 安裝本應(yīng)用之前,先編譯好未簽名的應(yīng)用包,然后在終端執(zhí)行工程里的腳本,目錄為:WorkScheduler/signTool/b_sign_hap_release.bat;
  2. 未連接wifi狀態(tài)下進(jìn)入應(yīng)用;
  3. 進(jìn)入首頁后連接wifi;
  4. 后臺(tái)判斷版本號(hào)后會(huì)下載新的升級(jí)包,并在頁面中給出彈窗詢問是否安裝,點(diǎn)擊“確定”按鈕;
  5. 應(yīng)用會(huì)安裝已經(jīng)下載的升級(jí)包,實(shí)現(xiàn)版本更新,安裝后會(huì)回到設(shè)備桌面,此時(shí)點(diǎn)擊應(yīng)用圖標(biāo),可以看到版本已經(jīng)是新版本了。
  6. 運(yùn)行自動(dòng)化測(cè)試用例時(shí),必須使用命令行裝包,不能使用ide自動(dòng)裝包,安裝自動(dòng)化測(cè)試包之前,先編譯好未簽名的測(cè)試包, 然后在終端執(zhí)行工程里的腳本,目錄為:WorkScheduler/signTool/a_sign_hap_release.bat;
  7. 運(yùn)行自動(dòng)化測(cè)試應(yīng)用時(shí)需要使用如下命令:
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             // 封裝各個(gè)功能接口
|---MainAbility
|   |---MainAbility.ets                     // 請(qǐng)求權(quán)限
|---pages
|   |---Index.ets                           // 首頁
|---util
|   |---Logger.ets                          // 日志文件
|---WorkSchedulerAbility
|   |---WorkSchedulerAbility.ets            // 延時(shí)任務(wù)觸發(fā)后的回調(diào)
鴻蒙HarmonyOS與OpenHarmony技術(shù)
+mau123789是v直接拿取

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

具體實(shí)現(xiàn)

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

  • 設(shè)置延時(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è)置延時(shí)任務(wù):在運(yùn)行示例時(shí)會(huì)在[MainAbility.ets] 通過WorkSchedulerSystem.startUpdateSample()方法調(diào)用workScheduler.startWork()建立任務(wù);
  • 下載更新包:當(dāng)任務(wù)條件滿足后,會(huì)在[WorkSchedulerAbility.ets]通過WorkSchedulerSystem.getNewHap()方法調(diào)用http.createHttp().request()接口下載需要的文件;
  • 保存更新包:通過WorkSchedulerSystem.saveFile()來實(shí)現(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)容決定是否提示用戶升級(jí);
  • 安裝更新包:在[WorkSchedulerAbility.ets] 通過WorkSchedulerSystem.installBundle()方法實(shí)現(xiàn),首先調(diào)用bundle.getBundleInstaller()獲取Installer對(duì)象,然后調(diào)用bundleInstall.install()接口實(shí)現(xiàn)裝包,完成升級(jí)。

審核編輯 黃宇

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

    關(guān)注

    81

    文章

    5372

    瀏覽量

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

    關(guān)注

    59

    文章

    2507

    瀏覽量

    43766
  • HarmonyOS
    +關(guān)注

    關(guān)注

    79

    文章

    2052

    瀏覽量

    32120
  • OpenHarmony
    +關(guān)注

    關(guān)注

    26

    文章

    3823

    瀏覽量

    18128
收藏 人收藏

    評(píng)論

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    請(qǐng)問delay_xms()延時(shí),會(huì)不會(huì)引起任務(wù)調(diào)度

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

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

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

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

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

    時(shí)調(diào)度思想在單片機(jī)應(yīng)用中的一個(gè)實(shí)例

    利用分時(shí)操作系統(tǒng)中的分時(shí)調(diào)度思想可以使一個(gè)多終端的系統(tǒng)快速響應(yīng)各終端的要求。本文首先介紹分時(shí)操作系統(tǒng)中的分時(shí)調(diào)度思想, 然后以程控交換機(jī)的控制系統(tǒng)為例, 在簡(jiǎn)介控
    發(fā)表于 07-17 16:03 ?26次下載

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

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

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

    針對(duì)當(dāng)前云任務(wù)調(diào)度算法在密碼云環(huán)境中無法實(shí)現(xiàn)任務(wù)實(shí)時(shí)處理的問題,提出一種基于滾動(dòng)優(yōu)化窗口的實(shí)時(shí)閾值調(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>算法

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

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

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

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