Android的NFC同时感应和读取标签数据 [英] Android NFC sensing and read tag data at the same time

查看:929
本文介绍了Android的NFC同时感应和读取标签数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于Android的NFC问题。

I have a question about the android NFC.

我已经做了有关读写的功能,但仍然有一个问题。

I have already done the function about read and write, but still have one problem.

我写的AAR在我的标签,第一感测之后,就可以启动我的申请。

I wrote the AAR in my tag, after first sensing, it can launch my application.

第二次检测(我的应用程序启动),我可以读取NFC标签中的数据。

Second time sensing (my application is launched), I can read the data from NFC tag.

是否有可能只是感应一次可以启动我的应用程序,并从标签中获取的数据?

Is it possible just sensing once that can launch my application and get the data from tag?

推荐答案

在AndroidManifest -

In AndroidManifest -

  <activity
        android:name=".TagDiscoverer"
        android:alwaysRetainTaskState="true"
        android:label="@string/app_name"
        android:launchMode="singleInstance"
        android:screenOrientation="nosensor" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />
            <action android:name="android.nfc.action.TECH_DISCOVERED" />
            <action android:name="android.nfc.action.TAG_DISCOVERED" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="text/plain" />
        </intent-filter>

        <meta-data
            android:name="android.nfc.action.TECH_DISCOVERED"/>
    </activity>

您应该​​开始OnCreate()中的NFC采用者。

you should initiate the NFC adopter in OnCreate()..

     /**
      * Initiates the NFC adapter
     */
  private void initNfcAdapter() {
    nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    mPendingIntent = PendingIntent.getActivity(this, 0,
        new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
   }

在OnResume()

现在...

Now in OnResume() ...

  @Override
  protected void onResume() {
  super.onResume();
  if (nfcAdapter != null) {
    nfcAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
  }
 }

这篇关于Android的NFC同时感应和读取标签数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆