1、HamonyOS 樣機獲取成功返回Oaid為00000000-0000-0000-0000-000000000000?
請求授權時需要觸發動態授權彈窗,看一下是不是沒有觸發授權彈窗。
可以參考以下代碼以及文檔:
// ets
import identifier from '@ohos.identifier.oaid';
import hilog from '@ohos.hilog';
import { BusinessError } from '@ohos.base';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import common from '@ohos.app.ability.common';@Entry
@Component
struct deviceDemo001 {build() {Column() {Text('測試').width('100%').backgroundColor('#131313').height(50).fontColor(Color.White).onClick(()=>{const atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();try {let context = getContext(this) as common.UIAbilityContext;atManager.requestPermissionsFromUser(context, ["ohos.permission.APP_TRACKING_CONSENT"]).then((data) => {if (data.authResults[0] == 0) {identifier.getOAID((err: BusinessError, data: string) => {if (err.code) {hilog.error(0x0000, 'testTag', '%{public}s', `get oaid failed, error: ${err.code} ${err.message}`);} else {const oaid: string = data;}});} else {}}).catch((err: BusinessError) => {})} catch(err) {}})}}
}
參考文檔:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/oaid-service-V5
開放匿名設備標識符(Open Anonymous Device Identifier, OAID,以下簡稱OAID):是一種非永久性設備標識符,基于開放匿名設備標識符,可在保護用戶個人數據隱私安全的前提下,向用戶提供個性化廣告,同時三方監測平臺也可以向廣告主提供轉化歸因分析。
媒體App、廣告平臺、三方監測平臺等開發者,可獲取設備上的OAID,您可基于OAID進行個性化廣告推薦或廣告轉化歸因分析。
OAID是基于華為自有算法生成的32位類UUID(Universally Unique Identifier)標識符,格式為xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx。
OAID的特性:
- OAID是設備級標識符,同一臺設備上不同的App獲取到的OAID值一樣。
- OAID的獲取受應用的“跨應用關聯訪問權限”開關影響:當應用的“跨應用關聯訪問權限”開關開啟時,該應用可獲取到非全0的有效OAID;當應用的“跨應用關聯訪問權限”開關關閉時,該應用僅能獲取到全0的OAID。
- 同一臺設備上首個應用開啟應用“跨應用關聯訪問權限”開關時,會首次生成OAID。
2、HarmonyOS 如何實現通過NFC實現手機給卡充值的功能?
需要的能力是使用NFC適配器建立連接,發送數據和接收數據,對應的業務場景就是使用NFC天線對公交進行充值,NFC讀寫CPU卡的部分,ISO-14443-4協議規范
標準NFC-Tag tag.TagInfo demo:
import tag from '@ohos.nfc.tag';
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import Want from '@ohos.app.ability.Want'export default class EntryAbility extends UIAbility {onCreate(want : Want, launchParam: AbilityConstant.LaunchParam) {// add other code here...// want is initialized by nfc service, contains tag info for this found taglet tagInfo : tag.TagInfo | null = null;try {tagInfo = tag.getTagInfo(want);} catch (error) {console.error("tag.getTagInfo catched error: " + error);}if (tagInfo == null || tagInfo == undefined) {console.log("no TagInfo to be created, ignore it.");return;}// get the supported technologies for this found tag.let isNfcATag = false;let isIsoDepTag = false;for (let i = 0; i < tagInfo.technology.length; i++) {if (tagInfo.technology[i] == tag.NFC_A) {isNfcATag = true;}if (tagInfo.technology[i] == tag.ISO_DEP) {isIsoDepTag = true;}// also check for technology: tag.NFC_B/NFC_F/NFC_V/NDEF/MIFARE_CLASSIC/MIFARE_ULTRALIGHT/NDEF_FORMATABLE}// use NfcA APIs to access the found tag.if (isNfcATag) {let nfcA : tag.NfcATag | null = null;try {nfcA = tag.getNfcATag(tagInfo);} catch (error) {console.error("tag.getNfcATag catched error: " + error);}// other code to read or write this found tag.}// use getIsoDep APIs to access the found tag.if (isIsoDepTag) {let isoDep : tag.IsoDepTag | null = null;try {isoDep = tag.getIsoDep(tagInfo);} catch (error) {console.error("tag.getIsoDep catched error: " + error);}// other code to read or write this found tag.}// use the same code to handle for "NfcA/NfcB/NfcF/NfcV/Ndef/MifareClassic/MifareUL/NdefFormatable".}
}
3、HarmonyOS css 部分語法會被標紅報錯?
文件是web應用打包之后的css文件
因為目前IDE本身僅支持最基本的那部分CSS語法,所以在項目打開會看見報錯標紅,經過測試雖然會報錯,但是不影響app的正常使用。
目前css支持的語法可以參考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/js-framework-syntax-css-V5
4、如何將pc系統剪切板里的內容粘貼到模擬器?
- 總體思路通過在模擬器中訪問PC端web頁面的方式,來實現文本的復制粘貼。
- PC端開啟web服務器
- 如果有現成的web服務器,把需要復制的文本文件放到web服務器下即可。
- macOS自帶apache服務器(推薦)
- 啟用服務:mac命令行執行sudo apachectl start服務啟動后,使用PC瀏覽器訪問http://127.0.0.1,能訪問頁面看到"It works!",說明服務啟動成功。
- 修改需要復制的文本apache服務的文件根目錄位于/Library/WebServer/Documents新建test.html文件,內容為需要復制的文本,拷貝到/Library/WebServer/Documents即可,PC端訪問地址http://127.0.0.1/test
- windows可下載、運行nginx應用
- nginx文件根目錄位于nginx/html,默認首頁為index.html,修改文本內容即可
5、HarmonyOS 關于ArkTS及so熱更新問題的咨詢?
在Android中很多應用會有熱更的需求,一般有兩種方案:
一種是差分法,可以更新java代碼和so代碼以及一些資源文件;
另一種是通過hook的方式運行時加載包外的so。想詢問一下HarmonyOS下是否有類似的機制,特別是是否允許從包外加載so
主要是為了解決已經上架的包有部分bug不容易簡單修復,需要修改arkts或者C/C++代碼, 但又不希望整包更換的情景
基于HarmonyOS應用統一分發的生態規則,不提供補丁的快速熱修復功能,上述相關訴求,通過高效的上架審核和應用版本更新機制進行保障。