在线观看www成人影院-在线观看www日本免费网站-在线观看www视频-在线观看操-欧美18在线-欧美1级

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

鴻蒙NEXT實戰開發:【截屏】

jf_46214456 ? 來源:jf_46214456 ? 作者:jf_46214456 ? 2024-03-07 16:02 ? 次閱讀

展示全屏截圖和屏幕局部截圖。通過[screenshot]模塊實現屏幕截圖 ,通過[window]模塊實現隱私窗口切換,通過[display]模塊查詢當前隱私窗口。

效果預覽

image.png

使用說明:

  1. 點擊右上角圖標打開彈窗,選擇截屏,展示全屏截圖;選擇局部截屏,選擇截屏區域,點擊右下角完成,展示局部截屏;
  2. 點擊滑塊切換窗口隱私模式,隱私模式下截屏會彈出提示,拒絕截屏。

具體實現

本示例通過screenshot接口實現屏幕截圖 ,通過window接口實現隱私窗口切換,通過display接口查詢當前隱私窗口。

  • 源碼鏈接:[Screenshot.ets]
/*

 * Copyright (c) 2022 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 screenshot from '@ohos.screenshot'

import { Logger } from './Logger'

import { getCurrentWindow } from './WindowPrivacy'



// 屏幕截圖 默認參數screenshotOptions為空時 截全屏

export function getScreenshot(screenshotOption = {}) {

  return screenshot.save(screenshotOption)

}



// 設置全屏展示 isFullScreen: boolean

export function setFullScreen(context: Context, isFullScreen: boolean) {

  getCurrentWindow(context)

    .then(res = > {

      res.setFullScreen(isFullScreen, (err) = > {

        if (err.code) {

          Logger.error('failed set full-screen mode cause: ' + JSON.stringify(err))

          return

        }

        Logger.info('success set full-screen mode')

      })

    })

}
  • [WindowPrivacy.ets]
/*

 * Copyright (c) 2022 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 window from '@ohos.window'

import display from '@ohos.display'

import { ResponseData } from '../models/ResponseData'

import { Logger } from './Logger'



// 獲取當前窗口

export function getCurrentWindow(context: Context) {

  return window.getTopWindow(context)

}



// 判斷隱私窗口

export function hasPrivate(): ResponseData {

  let currentDisplay = null

  try {

    currentDisplay = display.getDefaultDisplaySync()

  } catch (exception) {

    return { status: 'failed', errorMessage: JSON.stringify(exception) }

  }

  if (currentDisplay === null) {

    return { status: 'failed', errorMessage: 'get current display failed' }

  }

  let ret = undefined

  try {

    ret = display.hasPrivateWindow(currentDisplay.id)

  } catch (exception) {

    return { status: 'failed', errorMessage: JSON.stringify(exception) }

  }

  if (ret === undefined) {

    return { status: 'failed', errorMessage: 'ret is undefined' }

  }

  return ret ? { status: 'success', errorMessage: '', result: true } :

    { status: 'success', errorMessage: '', result: false }

}





// 設置隱私窗口

export function setWindowPrivacyMode(context: Context, windowPrivacyMode: boolean) {

  let currentWindow = null

  getCurrentWindow(context)

    .then(res = > {

      currentWindow = res

      try {

        currentWindow.setWindowPrivacyMode(windowPrivacyMode, (err) = > {

          if (err.code) {

            Logger.error('set window privacy mode failed cause: ' + JSON.stringify(err))

            return

          }

          Logger.info(`set window privacy mode success ${windowPrivacyMode}`)

        })

      } catch (exception) {

        Logger.info('set window mode failed cause: ' + JSON.stringify(exception))

      }

    })

}

062b7e9f99042d0461e287c5c0ee8749.png

審核編輯 黃宇

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 鴻蒙
    +關注

    關注

    59

    文章

    2542

    瀏覽量

    43830
收藏 人收藏

    評論

    相關推薦
    熱點推薦

    2024款鴻蒙OS 最新HarmonyOS Next_HarmonyOS4.0系列教程分享

    實戰,還包含了HarmonyOS 仿小米App實戰。詳情參考大綱或者目錄介紹。 根據華為鴻蒙生態推廣部門介紹,HarmonyOS4和未來的HarmonyOS5(HarmonyOS Next
    發表于 02-28 10:29

    鴻蒙實戰項目開發:【短信服務】

    、OpenHarmony 多媒體技術、Napi組件、OpenHarmony內核、Harmony南向開發鴻蒙項目實戰等等)鴻蒙(Harmony NE
    發表于 03-03 21:29

    名單公布!【書籍評測活動NO.47】HarmonyOS NEXT啟程:零基礎構建純血鴻蒙應用

    要在2000萬 。這一呼吁引起了全球開發者的關注,也意味著市場對HarmonyOS開發人才的需求將快速增長。 什么是純血鴻蒙 HarmonyOS NEXT,也被稱為純血
    發表于 10-14 14:36

    鴻蒙Flutter實戰:07混合開發

    # 鴻蒙Flutter實戰:混合開發 鴻蒙Flutter混合開發主要有兩種形式。 ## 1.基于har 將flutter module
    發表于 10-23 16:00

    名單公布!【書籍評測活動NO.56】極速探索HarmonyOS NEXT:純血鴻蒙應用開發實踐

    的各個關鍵領域。另外,書中還提供了基于HarmonyOS NEXT 的完整實戰項目和3個特色案例,并附帶了全套的源代碼。 本書適合鴻蒙應用開發工程師、移動應用
    發表于 01-20 16:53

    鴻蒙系統截圖怎么 在哪里操作

    華為鴻蒙操作系統發布已經過去將近一個月了,那么,華為鴻蒙系統截圖怎么鴻蒙系統
    的頭像 發表于 06-25 09:57 ?8954次閱讀

    鴻蒙系統怎么 5種方法的詳細介紹

    鴻蒙系統作為一個新系統,里面的玩法肯定也會與之前系統有一定的差別,很多小伙伴就不太清楚鴻蒙系統怎么
    的頭像 發表于 06-28 12:03 ?6.4w次閱讀

    鴻蒙系統功能在哪里

    華為鴻蒙系統發布后,目前為止很多小伙伴都升級了鴻蒙系統,是手機使用過程中一個很基礎的功能,那么鴻蒙系統
    的頭像 發表于 07-09 15:44 ?1.2w次閱讀

    屏幕功能

    屏幕功能
    發表于 05-26 15:25 ?15次下載

    淘寶與華為合作將基于HarmonyOS NEXT啟動鴻蒙原生應用開發

    1月25日,淘寶與華為舉辦鴻蒙合作簽約儀式,宣布將基于HarmonyOS NEXT啟動鴻蒙原生應用開發
    的頭像 發表于 01-26 16:14 ?1452次閱讀

    華為宣布HarmonyOS NEXT鴻蒙星河版開發者預覽面向開發者開放申請

    華為宣布HarmonyOS NEXT鴻蒙星河版開發者預覽面向開發者開放申請,這意味著鴻蒙生態進入第二階段,將加速千行百業的應用
    的頭像 發表于 01-29 16:42 ?1742次閱讀
    華為宣布HarmonyOS <b class='flag-5'>NEXT</b><b class='flag-5'>鴻蒙</b>星河版<b class='flag-5'>開發</b>者預覽面向<b class='flag-5'>開發</b>者開放申請

    鴻蒙開發教程

    去年8 月份華為發布會上,華為發布了HarmonyOS NEXT預覽版,宣布不再兼容安卓應用。大家期待的純血鴻蒙終于要來臨了,next 預覽版本現在已經開放申請渠道了,Next
    的頭像 發表于 01-31 17:11 ?1200次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發</b>教程

    華為pockets怎么

    華為Pocket S的方法有以下幾種。
    的頭像 發表于 03-06 16:06 ?2999次閱讀

    鴻蒙NEXT南向開發案例:【智能臺燈】

    鴻蒙南向開發之智能臺燈案例
    的頭像 發表于 04-03 18:00 ?1348次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>NEXT</b>南向<b class='flag-5'>開發</b>案例:【智能臺燈】

    HarmonyOS開發實例:【手勢

    基于手勢處理和能力,介紹了手勢的實現過程。樣例主要包括以下功能
    的頭像 發表于 04-11 22:38 ?1086次閱讀
    HarmonyOS<b class='flag-5'>開發</b>實例:【手勢<b class='flag-5'>截</b><b class='flag-5'>屏</b>】
    主站蜘蛛池模板: 久久黄视频 | 日本三级免费 | 永井玛丽亚中文在线观看视频 | 黄网在线免费观看 | 免费爱爱视频 | 日本3级视频 | 五月天免费在线播放 | 成在线人视频免费视频 | 老色99久久九九精品尤物 | 国产美女一级视频 | a资源在线| 三级第一页 | 国产一二三区在线 | 人人插人人插 | h在线观看视频免费网站 | 亚洲第一视频在线观看 | 国产香蕉75在线播放 | 国产婷婷综合丁香亚洲欧洲 | 七月婷婷在线视频综合 | 四虎影院免费视频 | 日本特级视频 | 免费观看理论片毛片 | 一区二区三区视频在线观看 | 欧美色视频网 | 国产好深好硬好爽我还要视频 | 欧美性猛交xxx嘿人猛交 | se94se亚洲欧美在线 | 亚洲卡5卡6卡7国色天香 | 亚洲综合色婷婷 | 国产精品久久久久影院色老大 | 色婷婷综合网 | 亚洲成网| 午夜小视频免费 | 国产精品久久久久久免费播放 | 国产1卡2卡三卡四卡网站 | 波多野结衣久久国产精品 | 一区二区三区高清在线观看 | 五月婷婷社区 | aa视频免费 | 欧美ol丝袜高跟秘书在线观看 | 婷婷激情综合五月天 |