Android Studi安卓读写NDEF智能海报源码

本示例使用的发卡器:https://item.taobao.com/item.htm?id=615391857885&spm=a1z10.5-c.w4002-21818769070.11.1f60789ey1EsPH

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:padding="3dp"tools:context=".NdefURLActivity"><androidx.appcompat.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="30dp"android:background="?attr/colorPrimary"app:navigationIcon="@drawable/baseline_arrow_back_ios_24"app:titleTextColor="@color/white"tools:ignore="MissingConstraints"tools:layout_editor_absoluteY="0dp"><TextViewandroid:id="@+id/TextViewlabelDispleft"android:layout_width="wrap_content"android:layout_height="match_parent"android:text="返回"android:textColor="@color/white"android:textSize="16sp"android:gravity="center"android:onClick="retmain" /><TextViewandroid:id="@+id/TextViewlabelDisp"android:layout_width="match_parent"android:layout_height="match_parent"android:text="NDEF_URL  "android:textColor="@color/white"android:textSize="16sp"android:gravity="center_horizontal|right|center"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="@+id/TextViewlabelDispleft"app:layout_constraintTop_toTopOf="parent" /></androidx.appcompat.widget.Toolbar><TextViewandroid:id="@+id/sample_text"android:layout_width="fill_parent"android:layout_height="150dp"android:padding="3dp"android:text="操作结果"android:textSize="12sp"android:background="@drawable/shape4border"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintBottom_toBottomOf="parent"/><ScrollViewandroid:id="@+id/scrollViewIC"android:layout_width="fill_parent"android:layout_height="0dp"android:layout_marginBottom="5dp"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintTop_toBottomOf="@+id/toolbar"app:layout_constraintBottom_toTopOf="@+id/sample_text"android:scrollbars="horizontal"><androidx.constraintlayout.widget.ConstraintLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:padding="3dp"         ><TextViewandroid:id="@+id/textlabletitle"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:text="标题:"android:textSize="16sp"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintTop_toTopOf="parent" /><EditTextandroid:id="@+id/Edittexttitle"android:layout_width="350dp"android:layout_height="wrap_content"android:textSize="16sp"android:gravity="left"android:hint="百度"app:layout_constraintBottom_toBottomOf="@+id/textlabletitle"app:layout_constraintLeft_toRightOf="@+id/textlabletitle"app:layout_constraintTop_toTopOf="@+id/textlabletitle" /><TextViewandroid:id="@+id/textlableprefix"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:text="前缀:"android:textSize="16sp"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintTop_toBottomOf="@+id/textlabletitle" /><Spinnerandroid:id="@+id/spin_Selurlprefix"android:layout_width="350dp"android:layout_height="wrap_content"android:entries="@array/NdefUrlPrefix"android:theme="@style/my_spinner_style"app:layout_constraintBottom_toBottomOf="@+id/textlableprefix"app:layout_constraintLeft_toRightOf="@+id/textlableprefix"app:layout_constraintTop_toTopOf="@+id/textlableprefix" /><EditTextandroid:id="@+id/edittexturl"android:layout_width="match_parent"android:layout_height="80dp"android:layout_marginLeft="38dp"android:layout_marginTop="10dp"android:background="@drawable/shape4border"android:gravity="left"android:inputType="textCapCharacters"android:maxLines="8"android:hint="baidu.com"android:textSize="12sp"app:layout_constraintLeft_toRightOf="@+id/textlableprefix"app:layout_constraintTop_toBottomOf="@+id/spin_Selurlprefix" /><Buttonandroid:id="@+id/butt_writeurltag"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_marginTop="8dp"android:text="将以上URL写入标签"android:textSize="14sp"android:onClick="writeurltag"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintTop_toBottomOf="@+id/edittexturl" /></androidx.constraintlayout.widget.ConstraintLayout></ScrollView></androidx.constraintlayout.widget.ConstraintLayout>

 

package com.usbreadertest;import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;import androidx.appcompat.app.AppCompatActivity;import com.reader.ourmifare;public class NdefURLActivity extends AppCompatActivity {private TextView tv;private Spinner ctrselefix;private EditText ctrtitle;private EditText ctrurlinf;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_ndef_url);androidx.appcompat.widget.Toolbar toolbar=findViewById(R.id.toolbar);setSupportActionBar(toolbar);tv = findViewById(R.id.sample_text);tv.setText("操作结果");ctrselefix=findViewById(R.id.spin_Selurlprefix);ctrselefix.setSelection(2);ctrurlinf=findViewById(R.id.edittexturl);ctrurlinf.requestFocus();ctrtitle=findViewById(R.id.Edittexttitle);}@Overridepublic void onBackPressed(){super.onBackPressed();finish();}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {if(item.getItemId()==android.R.id.home){finish();return true;}return super.onOptionsItemSelected(item);}public void retmain(View view){finish();}public void writeurltag(View view)  throws Exception  {String languagecodestr="en";byte[] languagecodebyte= languagecodestr.getBytes("gb2312");int languagecodestrlen=languagecodebyte.length;String urltstr=ctrurlinf.getText().toString().trim();if(urltstr.length()<1){tv.setText("请输入要写入的网址!");ctrurlinf.requestFocus();return;}byte[] urlbyte=urltstr.getBytes();int  urllen=urlbyte.length;String titletstr=ctrtitle.getText().toString().trim();byte[] titlebyte=titletstr.getBytes();int titlelen=titlebyte.length;byte urlheaderindex = (byte)(ctrselefix.getSelectedItemId());ourmifare.tagbufclear();    //先清空NDEF数据缓冲byte status=ourmifare.tagbufadduri(languagecodebyte,languagecodestrlen,titlebyte,titlelen,urlheaderindex,urlbyte,urllen);   //生成NDEF数据缓冲if (status==0){int tagtype=NdefTextActivity.CheckCardType();    //检测发卡器上标签类型if(tagtype==-1){tv.setText("发卡器感应区未发现有效的NDEF标签!");return;}byte[] mypiccserial=new byte[8];status=NdefTextActivity.WriteTag(tagtype,mypiccserial);   //将已生成的NDEF数据写入不同的标签内String dispinfo=NdefTextActivity.dispwritetag(status ,mypiccserial,tagtype);tv.setText(dispinfo);}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/411448.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

七陌API对接实战:外呼接口及通话记录推送

通过白码低代码开发平台对接七陌外呼接口&#xff0c;实现选择客户进行外呼&#xff0c;并保存通话记录的功能。 外呼接口实现&#xff1a; 官方接口文档&#xff1a;http://developer.7moor.com/v2docs/dialout/ 1、对接数据查询 向七陌商务索取到七陌用户中心账号密码&a…

Servlet 预览pdf

一、背景 上篇文章介绍了图片的预览&#xff0c;这篇我们介绍下 pdf 文件的预览&#xff0c;pdf 预览在实际开发中用的还是比较多的&#xff0c;比如很多文件协议、合同都是用pdf 格式&#xff0c;协议预览就需要我们做 pdf 预览了。 二、实操 其实在上篇文章最后已经说了常用…

django后台手机号加密存储

需求&#xff1a; 1 &#xff1a;员工在填写用户的手机号时&#xff0c;直接填写&#xff0c;在django后台中输入 2&#xff1a;当员工在后台确认要存储到数据库时&#xff0c;后台将会把手机号进行加密存储&#xff0c;当数据库被黑之后&#xff0c;手机号字段为加密字符 3&am…

新能源汽车智慧充电桩解决方案:智慧化综合管理与数字化高效运营

一、方案概述 TSINGSEE青犀&触角云新能源汽车智慧充电桩解决方案基于管理运营平台&#xff0c;覆盖业务与应用、数据传输与梳理、多端开发、搭建等模块&#xff0c;融合AI、5G、Wi-Fi 、移动支付等技术&#xff0c;实现充电基础设施由数字化向智能化演进&#xff0c;通过构…

day4:多点通信与域套接字

思维导图 使用tftp实现简单文件的上传 #include <head.h> #define SER_PORT 69 #define SER_IP "192.168.125.223" int link_file() {int sfdsocket(AF_INET,SOCK_DGRAM,0);if(sfd-1){perror("socket error");return -1;}return sfd; } int filedow…

多级树形结构查询 - 递归

表结构 CREATE TABLE pms_category (cat_id BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT 分类id,name CHAR(50) NULL DEFAULT NULL COMMENT 分类名称 COLLATE utf8mb4_general_ci,parent_cid BIGINT(20) NULL DEFAULT NULL COMMENT 父分类id,cat_level INT(11) NULL DEFAULT …

【架构】docker实现3主3从架构配置【案例1/4】

一&#xff0c;集群规划及准备工作 架构实现&#xff1a;Redis3主3从 二&#xff0c;搭建命令 第一步&#xff0c;创建6台服务&#xff1a; docker run -d --name redis-node-1 --net host --privilegedtrue -v /data/redis/share/redis-node-1:/data redis:6.0.8 --clust…

VSCode编写 C/C++ 程序

VSCode 全称 Visual Studio Code&#xff0c;是微软出的一款轻量级代码编辑器&#xff0c;免费、开源而且功能强大。它支持几乎所有主流的程序语言的语法高亮、智能代码补全、自定义热键、括号匹配、代码片段、代码对比 Diff、GIT 等特性&#xff0c;支持插件扩展&#xff0c;并…

深度学习记录--梯度检验

数值逼近 为了对梯度进行检验&#xff0c;需要计算近似误差值来接近梯度 对于单边误差和双边误差公式&#xff0c;其中双边误差与真实梯度相差更小&#xff0c;故一般采用双边误差公式 双边误差 公式&#xff1a; 梯度检验(gradient checking) 对于成本函数&#xff0c;求出…

canvas绘制美队盾牌

查看专栏目录 canvas示例教程100专栏&#xff0c;提供canvas的基础知识&#xff0c;高级动画&#xff0c;相关应用扩展等信息。canvas作为html的一部分&#xff0c;是图像图标地图可视化的一个重要的基础&#xff0c;学好了canvas&#xff0c;在其他的一些应用上将会起到非常重…

记一次 .NET某道闸收费系统 内存溢出分析

一&#xff1a;背景 1. 讲故事 前些天有位朋友找到我&#xff0c;说他的程序几天内存就要爆一次&#xff0c;不知道咋回事&#xff0c;找不出原因&#xff0c;让我帮忙看一下&#xff0c;这种问题分析dump是最简单粗暴了&#xff0c;拿到dump后接下来就是一顿分析。 二&…

力扣1929.数组串联

前言 虽然力扣对我来说很难&#xff0c;但只要每天刷一点&#xff0c;就会慢慢增强能力&#xff0c;总有一天刷动力扣的难题&#xff0c;所以说&#xff0c;今天也是刷力扣的一天。 &#x1f606;&#x1f606; /** * Note: The returned array must be malloced, assume call…