当前位置: 首页 > news >正文

安全文化企业示范企业评价标准seo百度站长工具

安全文化企业示范企业评价标准,seo百度站长工具,最成功设计 网站,用地方名字做网站前言 最近搞了个设备,需求是读取m1卡,厂家给了个安卓原生demo,接入arr插件如下,接入后发现还是少了一部分代码,设备服务调起后触发刷卡无法发送到uniapp里。 中间是一些踩坑记录,最后面是解决办法&#xf…

前言

最近搞了个设备,需求是读取m1卡,厂家给了个安卓原生demo,接入arr插件如下,接入后发现还是少了一部分代码,设备服务调起后触发刷卡无法发送到uniapp里。
中间是一些踩坑记录,最后面是解决办法,赶时间直接拉到最后

安卓原生广播

demo中的NfcService其中有一个onDataReceived方法,最终调用了LocalBroadcastManager 发送广播

protected void onDataReceived(final ComBean ComRecData) {Log.d(TAG, "发送消息!");LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(getApplicationContext());Intent intent = new Intent(NfcAction.ACTION_NOTIFY_CARD_NUMBER);intent.putExtra(NfcAction.KEY_NOTIFY_DECIMAL_CARD_NUMBER, decimal);intent.putExtra(NfcAction.KEY_NOTIFY_DECIMAL_REVERSE_CARD_NUMBER, decimalReverse);intent.putExtra(NfcAction.KEY_NOTIFY_ORIGINAL_CARD_NUMBER, originHex);intent.putExtra(NfcAction.KEY_NOTIFY_EIGHT_HEX_CARD_NUMBER, eightHex);intent.putExtra(NfcAction.KEY_NOTIFY_EIGHT_HEX_REVERSE_CARD_NUMBER, eightHexReverse);intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);localBroadcastManager.sendBroadcast(intent);Log.d(TAG, "发送消息成功!");
}

MainActivityonCreate里有接收广播

val nfcCardReceiver = NfcCardReceiver()
val intentFilter = IntentFilter()
intentFilter.addAction(NfcAction.ACTION_NOTIFY_CARD_NUMBER)
LocalBroadcastManager.getInstance(this).registerReceiver(nfcCardReceiver, intentFilter)

NfcCardReceiver

package com.rt.nfclibdemoimport android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import com.rt.lib_nfc.NfcAction
import org.greenrobot.eventbus.EventBusclass NfcCardReceiver: BroadcastReceiver() {override fun onReceive(p0: Context?, p1: Intent?) {if (p1 != null) {val card = p1.getStringExtra(NfcAction.KEY_NOTIFY_ORIGINAL_CARD_NUMBER)val card2 = p1.getStringExtra(NfcAction.KEY_NOTIFY_DECIMAL_CARD_NUMBER)val card3 = p1.getStringExtra(NfcAction.KEY_NOTIFY_DECIMAL_REVERSE_CARD_NUMBER)val card4 = p1.getStringExtra(NfcAction.KEY_NOTIFY_EIGHT_HEX_CARD_NUMBER)val card5 = p1.getStringExtra(NfcAction.KEY_NOTIFY_EIGHT_HEX_REVERSE_CARD_NUMBER)//跟ui绑定的东西,忽略掉EventBus.getDefault().post(CardBean(card!!, card2!!, card3!!, card4!!, card5!!))Log.e("TAG", "onReceive: " + card + "---" + card2 + "---" + card3 + "---" + card4 + "---" + card5)}}
}

根据以往的经验写出如下代码,结果是失败的

const mainActivity = plus.android.runtimeMainActivity();
const NfcAction = plus.android.importClass('com.rt.lib_nfc.NfcAction');
var nfcCardReceiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {onReceive: function(context, intent) { //实现onReceiver回调函数plus.android.importClass(intent);console.log('context, intent ->', context, intent);console.log('intent.getAction() ->', intent.getAction());}
const IntentFilter = plus.android.importClass('android.content.IntentFilter');
const filter = new IntentFilter();
filter.addAction(NfcAction.ACTION_NOTIFY_CARD_NUMBER); //监听
let LocalBroadcastManager = plus.android.importClass('androidx.localbroadcastmanager.content.LocalBroadcastManager');
let localBroadcastManager = LocalBroadcastManager.getInstance(mainActivity);
localBroadcastManager.registerReceiver(nfcCardReceiver, filter);

最终结果是控制台无输出,
adb shell catlog抓到的日志是个null
在这里插入图片描述找了很久很久后,找到了个栗子,据说绑定不成功的原因是io.dcloud.android.content.BroadcastReceiver这个东西是抽象类,无法实现,只能用io.dcloud.feature.internal.reflect.BroadcastReceiver然而替换后还是不行,就是无法监听LocalBroadcastManager,又找了很久资料,找了无数篇垃圾文章后,找了原生安卓的很多文章后,终于找到了个办法,不用LocalBroadcastManager使用另一种方法发送,接收广播

最终方案

不使用LocalBroadcastManager发生监听广播
使用getApplicationContext().sendBroadcast(intent);发送广播
使用mainActivity.registerReceiver(nfcCardReceiver, filter);监听广播
首先将NfcService->onDataReceived改造,在原有基础上增加,更改后记得重新打成arr,然后重打自定义基座才能生效

protected void onDataReceived(final ComBean ComRecData) {Log.d(TAG, "发送消息!");LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(getApplicationContext());Intent intent = new Intent(NfcAction.ACTION_NOTIFY_CARD_NUMBER);intent.putExtra(NfcAction.KEY_NOTIFY_DECIMAL_CARD_NUMBER, decimal);intent.putExtra(NfcAction.KEY_NOTIFY_DECIMAL_REVERSE_CARD_NUMBER, decimalReverse);intent.putExtra(NfcAction.KEY_NOTIFY_ORIGINAL_CARD_NUMBER, originHex);intent.putExtra(NfcAction.KEY_NOTIFY_EIGHT_HEX_CARD_NUMBER, eightHex);intent.putExtra(NfcAction.KEY_NOTIFY_EIGHT_HEX_REVERSE_CARD_NUMBER, eightHexReverse);intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);Log.d(TAG, "发送localBroadcastManager消息");//原来的发送广播语句//localBroadcastManager.sendBroadcast(intent);Log.d(TAG, "发送getApplicationContext消息");//新增的关键语句getApplicationContext().sendBroadcast(intent);Log.d(TAG, "发送消息成功!");
}

uniapp部分

registerReceiver(){const that = this;const Log = plus.android.importClass('android.util.Log');Log.d('NfcApp', '1');const mainActivity = plus.android.runtimeMainActivity();const NfcAction = plus.android.importClass('com.rt.lib_nfc.NfcAction');const nfcCardReceiverFunc = {  onReceive: function(context, intent) { //实现onReceiver回调函数  plus.android.importClass(intent);console.log('context, intent ->', context, intent);console.log('intent.getAction() ->', intent.getAction());console.log('回调成功!');that.cardData = {};let card1 = intent.getStringExtra(NfcAction.KEY_NOTIFY_ORIGINAL_CARD_NUMBER);let card2 = intent.getStringExtra(NfcAction.KEY_NOTIFY_DECIMAL_CARD_NUMBER);let card3 = intent.getStringExtra(NfcAction.KEY_NOTIFY_DECIMAL_REVERSE_CARD_NUMBER);let card4 = intent.getStringExtra(NfcAction.KEY_NOTIFY_EIGHT_HEX_CARD_NUMBER);let card5 = intent.getStringExtra(NfcAction.KEY_NOTIFY_EIGHT_HEX_REVERSE_CARD_NUMBER);console.log('返回数据->',card1, card2, card3, card4, card5);if(card1 == 'AABB0600000001060007'){return;}//最终返回的数据that.cardData = { card1, card2, card3, card4, card5 };}};const nfcCardReceiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', nfcCardReceiverFunc);const IntentFilter = plus.android.importClass('android.content.IntentFilter');const filter = new IntentFilter();Log.d('NfcApp', '2');filter.addAction(NfcAction.ACTION_NOTIFY_CARD_NUMBER); //监听Log.d('NfcApp', '3');let res = mainActivity.registerReceiver(nfcCardReceiver, filter);Log.d('NfcApp', '4');Log.d('NfcApp', '绑定成功???')//解除绑定,暂未实现//unregisterReceiver
},

重新打包,重新运行后即可接到this.cardData返回的值了

http://www.hkea.cn/news/84959/

相关文章:

  • 专业做酒店网站关键词优化排名软件流量词
  • 做网站推广代理上海网络推广服务
  • wordpress可以做大吗搜索引擎优化的英语简称
  • 民治专业做网站公司中国企业500强排行榜
  • 潍坊 公司 网站seo点击排名器
  • 网站可以做赌博广告建站宝盒
  • 运城市做网站英文seo外链
  • 江宁网站建设如何建立网上销售平台
  • 淄博企业网站建设有限公司搜索引擎关键词竞价排名
  • 网站的优点企业专业搜索引擎优化
  • 哪里有软件开发培训机构无锡seo培训
  • 网站怎么做反链seo是什么品牌
  • 技术型网站做哪一种好软文范例大全100
  • 百度搜索什么关键词能搜到网站seo高效优化
  • 网站搭建分站需要多少钱互联网营销策划
  • 音乐网站的音乐怎么做seo先上排名后收费
  • 清河做网站报价seo实战培训王乃用
  • wordpress 回收站在哪个文件夹营销方式和手段
  • 垂直型电商网站如何做快速排名软件哪个好
  • 做产品推广有网站比较好的免费自助建站平台
  • 番禺网站建设公司排名百度推广页面投放
  • 沈阳做微网站百度收录刷排名
  • 网站建设与管理技术发展seo是什么意思如何实现
  • 手机游戏开发制作公司最新seo视频教程
  • 网站优化过度被k长春seo排名公司
  • wordpress移除谷歌字体seo网站推广与优化方案
  • 十大景观设计公司排名seo权重查询
  • 水友做的yyf网站十大免费引流平台
  • 东莞公司网站制作百度识图网页版 在线
  • 企业级网站内容管理解决方案网站关键词快速排名服务