
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源 去关联
随着物联网时代的到来,鸿蒙发展越来越好,万物互联的时代即将到来。接下来将会讲讲我接触鸿蒙FA开发。
鸿蒙FA“NFC碰一碰”主要是利用NFC“碰一碰”唤起鸿蒙FA应用,根据NFC通信拿到的设备信息,然后登录关联华为账号,进行配网,配网成功后就可以实现远程控制。
::: hljs-left
@Override
public void onStart(Intent intent) {
intent.setParam("window_modal",3);
HmsBridge.getInstance().initBridge(this);
// 获取sn和sessionId
String nanSessionId = intent.getStringParam("nanSessionId");
// 注册配网har包
NetConfigAbility.register(this, nanSessionId);
Object businessInfo = intent.getParams().getParam("businessInfo");
String sn = "";
if (businessInfo != null) {
ZSONObject businessInfoZson = ZSONObject.classToZSON(businessInfo);
sn = businessInfoZson.getZSONObject("params").getString("");
}
super.onStart(intent);
}
:::
@Override
// Fa正在运行,又重新扫一次
public void onNewIntent(Intent intent) {
// 获取sn和sessionId
String nanSessionId = intent.getStringParam("nanSessionId");
Object businessInfo = intent.getParams().getParam("businessInfo");
String sn = "";
if (businessInfo != null) {
ZSONObject businessInfoZson = ZSONObject.classToZSON(businessInfo);
sn = businessInfoZson.getZSONObject("params").getString("");
}
}
下面是华为的登录授权接口和退出接口。
// -------------------华为授权登录----------------------
引入鸿蒙sdk
import {HuaweiIdAuthParamsHelper, HuaweiIdAuthManager, OPENID, PROFILE, GAMES, Scope} from '@hmscore/hms-js-account'
signIn: function () {
var that = this
// 新增scopeList
var scopeList = new Array();
scopeList.push(OPENID);
scopeList.push(PROFILE);
var healthbehavior = new Scope("https://www.huawei.com/healthkit/extend/healthbehavior.read");
var hearthealthsleep = new Scope("https://www.huawei.com/healthkit/extend/hearthealthsleep.read");
var fatreduction = new Scope("https://www.huawei.com/healthkit/extend/fatreduction.read");
var sport = new Scope("https://www.huawei.com/healthkit/extend/sport.read");
scopeList.push(healthbehavior);
scopeList.push(hearthealthsleep);
scopeList.push(fatreduction);
scopeList.push(sport);
var opencloud = new Scope("https://www.huawei.com/auth/smarthome/opencloud");
scopeList.push(opencloud);
var signInOption = new HuaweiIdAuthParamsHelper().setId().setProfile().setMobileNumber().setAuthorizationCode().setScopeList(scopeList).build();
console.error(JSON.stringify(signInOption));
HuaweiIdAuthManager.getAuthApi().getSignInIntent(signInOption).then((result)=>{
var authCode = result.serverAuthCode;
var accessToken = result.accessToken;
var unionId = result.unionId;
}).catch((error)=>{
});
},
signOut: function () {
HuaweiIdAuthManager.getAuthApi().signOut().then((result)=>{
}).catch((error) => {
console.error("signout fail");
});
},
在第二步骤获取的nanSessionId,如果不是NAN_DEVICE_NOT_FOUND,那么可以走NAN配网流程,否则走Ap配网。具体配网步骤如
下:
引入华为的配网模块。
![cc.jpg]
解决方法是让某个视图稍微延时渲染。
这种情况使用div的属性show会解决这个问题,用if的时候会改变渲染树的结构,使用show避免这个问题。
需要先清除绘制,然后在进行绘制