在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:AndroidNFC开源软件地址:https://gitee.com/leohan1992/AndroidNFC开源软件介绍:AndroidNFCa base activity for use nfc dependencyMaven <dependency> <groupId>xyz.leohan</groupId> <artifactId>AndroidNFC</artifactId> <version>1.0.0</version> <type>pom</type></dependency> Gradle compile 'xyz.leohan:AndroidNFC:1.0.0' How to Use
public class MyActivity extends NfcActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override protected void onNfcTouch() { //this method will called when a NFC tag touched the phone and can be analysed //we can get NFC tag id here; }}
<activity android:name=".yourActivityName" android:configChanges="keyboardHidden|orientation|screenSize" android:launchMode="singleTask"> <intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="*/*" /> </intent-filter> </activity>
void readNfcContent();//can read message from NFC tagboolean writeNfc(String msg);//write something to NFC tagboolean deleteNfc(); //clear NFC tag Samplepublic class MainActivity extends NfcActivity { private TextView tvContent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvContent = (TextView) findViewById(R.id.tv_content); } @Override protected void onNfcTouch() { Log.i("nfc","ontouch"); tvContent.setText("NFC TagId:" + getTagId()); } public void readNfc(View view) { String s = null; try { //read nfc content from tag; s = this.readNfcContent(); } catch (Exception e) { e.printStackTrace(); } tvContent.setText(s); } public void writeNfcContent(View view) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String content = dateFormat.format(System.currentTimeMillis()); try { //write something to tag; this.writeNfc(content); } catch (Exception e) { e.printStackTrace(); } } public void clearNfc(View view) { try { //clear nfcContent this.deleteNfc(); } catch (Exception e) { e.printStackTrace(); } }}
Contact Meyou can sended me an e-mail :[email protected] |
请发表评论