wordpress 流量,宁波seo推广费用,东莞非凡网站建设,怎样刷新网站华为鸿蒙手表开发之动态生成二维码
前言#xff1a;
最近入职新公司#xff0c;由于之前的哥们临时离职#xff0c;走得很突然#xff0c;所以没有任何交接和文档#xff0c;临时顶上公司手表应用的上架#xff0c;更换了新的密钥和key之后重新测试功能和流程#xff…华为鸿蒙手表开发之动态生成二维码
前言
最近入职新公司由于之前的哥们临时离职走得很突然所以没有任何交接和文档临时顶上公司手表应用的上架更换了新的密钥和key之后重新测试功能和流程基本上没啥大问题华为那边的工作人员也测试通过了但是说隐私政策页面有一点问题内容有几个错误点我检查了一下App中的隐私政策发现是本地写死的页面于是询问华为的工作人员该如何修改他们给出一个意见用二维码生成一个页面用户和测试人员扫码就可以加载对应的页面而且这个url地址里面的内容是动态的可以随意修改不需要App频繁改动对于后期的审核和上架基本上是一步到位于是简单的学习了一下官方文档百度查询了一下资料生成了一个二维码界面。
1.新建一个隐私政策页面
/*** authortest* date2023/9/26 17:14* description隐私政策*/
public class PrivacyPolicyQRCodeAbility extends Ability {Overridepublic void onStart(Intent intent) {super.onStart(intent);super.setMainRoute(PrivacyPolicyQRCodeSlice.class.getName());}
}2.生成二维码及扫描页面
步骤如下
初始化view: initIView()初始化二维码引擎VisionManager.init(PrivacyPolicyQRCodeSlice.this, connectionCallback);二维码连接回调ConnectionCallback connectionCallback new ConnectionCallback()连接成功后生成二维码createQRCode(qrCodeUrlTxt);在界面退出时销毁引擎VisionManager.destroy();
package com.xxx.hwwear.slice;import com.elvishew.xlog.XLog;
import com.yadea.hwwear.BuildConfig;
import com.yadea.hwwear.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Image;
import ohos.ai.cv.common.ConnectionCallback;
import ohos.ai.cv.common.VisionManager;
import ohos.ai.cv.qrcode.IBarcodeDetector;
import ohos.media.image.ImageSource;
import ohos.media.image.PixelMap;
import ohos.media.image.common.PixelFormat;/*** authornjb* date2023/9/26 17:14* description扫描二维码进入隐私政策页面*/
public class PrivacyPolicyQRCodeSlice extends AbilitySlice {Image codeImage;Overridepublic void onStart(Intent intent) {super.onStart(intent);super.setUIContent(ResourceTable.Layout_ability_service_protocol_qr_code);initView();}private void initView() {codeImage (Image) findComponentById(ResourceTable.Id_imgQrCode);}Overridepublic void onActive() {super.onActive();VisionManager.init(PrivacyPolicyQRCodeSlice.this, connectionCallback);}Overridepublic void onForeground(Intent intent) {super.onForeground(intent);}Overrideprotected void onBackground() {super.onBackground();VisionManager.destroy();}ConnectionCallback connectionCallback new ConnectionCallback() {Overridepublic void onServiceConnect() {String qrCodeUrlTxt https://developer.huawei.com/consumer/cn/harmonyos;//连接成功生成二维码createQRCode(qrCodeUrlTxt);}Overridepublic void onServiceDisconnect() {if (BuildConfig.DEBUG) {XLog.d(Vision onServiceDisconnect);}}};/*** 创建二维码** param barText 需要生成二维码的字符串*/private void createQRCode(String barText) {//实例化接口获取二维码侦测器IBarcodeDetector barcodeDetector VisionManager.getBarcodeDetector(PrivacyPolicyQRCodeSlice.this);//定义码生成图像的尺寸final int SAMPLE_LENGTH getLayoutParams().width;//根据图像的大小分配字节流数组的空间byte[] byteArray new byte[SAMPLE_LENGTH * SAMPLE_LENGTH * 4];//调用IBarcodeDetector的detect()方法根据输入的字符串信息生成相应的二维码图片字节流barcodeDetector.detect(barText, byteArray, SAMPLE_LENGTH, SAMPLE_LENGTH);//释放侦测器barcodeDetector.release();//通过SourceOptions指定数据源的格式信息ImageSource.SourceOptions srcOpts new ImageSource.SourceOptions();//定义图片格式srcOpts.formatHint image/png;//创建图片源ImageSource imgSource ImageSource.create(byteArray, srcOpts);//创建图像解码选项ImageSource.DecodingOptions decodingOpts new ImageSource.DecodingOptions();decodingOpts.desiredPixelFormat PixelFormat.ARGB_8888;//通过图片源创建PixelMapPixelMap pMap imgSource.createPixelmap(decodingOpts);//赋值到图片标签codeImage.setPixelMap(pMap);//释放资源barcodeDetector.release();imgSource.release();if (pMap ! null) {pMap.release();}//断开与能力引擎的连接VisionManager.destroy();}
}3.生成二维码界面布局
?xml version1.0 encodingutf-8?
DirectionalLayoutxmlns:ohoshttp://schemas.huawei.com/res/ohosohos:heightmatch_parentohos:widthmatch_parentohos:alignmentcenterohos:orientationverticalImageohos:id$id:imgQrCodeohos:heightmatch_parentohos:widthmatch_parentohos:layout_alignmentcenter//DirectionalLayout4.点击隐私政策按钮跳转页面
richText.addTouchEventListener((param1Component, param1TouchEvent) - {Intent intent new Intent();intent.setOperation((new Intent.OperationBuilder()).withBundleName(getBundleName())//隐私政策.withAbilityName(PrivacyPolicyQRCodeAbility.class.getName()).build());ProtocolAbilitySlice.this.startAbility(intent);return false;
}, 29, 34);5.配置页面
{name: com.xxx.hwwear.PrivacyPolicyQRCodeAbility,description: $string:qrcodeabilityslice_description,icon: $media:icon,label: $string:entry_QRCodeAbilitySlice,launchType: standard,orientation: unspecified,type: page
},6.实现的效果如下 7.扫码后的效果截图如下 8.总结
这里是以华为鸿蒙OS应用开发官网举例这里的url可以随意动态切换如果有个接口能提供这个地址更好当然一般这些都不会经常改动里面的内容后台可以随时修改对于App或者手表应用都值得推荐使用简单方便本文基本上都是从0开始开发的由于之前是做Android开发的而且使用的是旧的Java语法基本上没有遇到大的问题当然其中的小问题还是有的.这里不是讲解让大家去学习新语言如果不是工作需要我不会接触鸿蒙和学习这些而是记录一下工作中遇到的实际问题后面等我大致了解清楚后再进行分享要不然盲目学习会令人头疼学完没有项目实战也是白搭不推荐大家学太多东西。我只是工作需要而已打卡收工关机睡觉。
下一篇讲解如何将鸿蒙手表应用线上包通过adb install的方式安装到本地手表上这里其实也是遇到了几个问题都是在工作人员的指导下顺利完成这里不得不说华为的工作人员态度极好回复也很快基本上有问题都是远程全面指导非常感谢