首页
学习
活动
专区
圈层
工具
发布

NFC读写
EN

Stack Overflow用户
提问于 2011-09-06 20:43:43
回答 2查看 2.7K关注 0票数 0

我正在编写一个使用Nexus S读写标签的安卓应用程序。我有两个不同的活动,一个是读的,另一个是写的,它们都是在各自的上下文中调用的。我的清单如下所示:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="bri.nfc.NfcTagReaderV1"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="10" />
    <uses-permission android:name="android.permission.NFC"/>
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".NFCTagReaderV1Activity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.example.android.nfc.TagViewer">
            <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
            <data android:mimeType="text/*" />
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
            <data android:scheme="http" />
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>
    <activity android:name="bri.nfc.writetag.WritetagActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
            <data android:mimeType="text/*" />
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
            <data android:scheme="http" />
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>
</application>
</manifest>

在我执行时,这些活动是随机调用的。一次调用标记查看器活动,另一次调用写标记活动。

我要求我的应用程序应该在读取时调用"tagviewer activity“,在写入时调用"writetag activity”。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-09-06 22:58:07

你不需要为你的"writetag活动“声明一个意图过滤器。相反,您需要使用前台调度系统。

下面的链接会将您带到Android Dev页面,该页面描述了如何实现前台调度系统。它的实现非常简单。

http://developer.android.com/guide/topics/nfc/index.html#foreground-dispatch

当newIntent-event被触发时,您就可以将数据写入NFC标记。要在NFC标签上写入数据,请使用此链接http://developer.android.com/guide/topics/nfc/index.html#write

这就是我在我的应用程序中做这件事的方式,它工作得很好。

票数 0
EN

Stack Overflow用户

发布于 2014-04-13 22:54:16

当你的活动恢复时,你应该在你的ActivityClass.For的OnResume方法()中使用前台调度,读标签,跟随这个链接,Reading NFC Tag With ForeGround Dispatch.And,同时写,你应该再次为WritingActivity设置前台调度。不要忘记在Activity.So的OnPause方法中停止前台调度,因为一次只有1个活动将注册前台调度

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7320125

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档