首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NFC -无法检测到标签

NFC -无法检测到标签
EN

Stack Overflow用户
提问于 2013-08-01 16:39:41
回答 1查看 1.2K关注 0票数 0

未调用onNewIntent(Intent intent)方法。

我尝试的代码是

代码语言:javascript
复制
public class NfcTagDetector extends Activity{

private NfcAdapter mNfcAdapter;
private PendingIntent pendingIntent;
private IntentFilter[] intentFiltersArray;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.detect_tag);
    pendingIntent = PendingIntent.getActivity(
            this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    IntentFilter discovery=new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);        
    IntentFilter techDetected = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);

    // Intent filters for writing to a tag
    intentFiltersArray = new IntentFilter[] { discovery,ndefDetected,techDetected };
}

public void onPause() {
    super.onPause();
    mNfcAdapter.disableForegroundDispatch(this);
}

public void onResume() {
    super.onResume();
    mNfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFiltersArray, null);
}

@Override
protected void onNewIntent(Intent intent) {
    // TODO Auto-generated method stub
    super.onNewIntent(intent);
    Log.e("TAP", "onNewIntent");
}

}

和AndroidManifest.xml

代码语言:javascript
复制
<activity android:name="com.example.detect.NfcTagDetector" >
        <intent-filter>
            <action android:name="android.nfc.action.TECH_DISCOVERED" />

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

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

nfc_tech_filter.xml文件是

代码语言:javascript
复制
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
    <tech>android.nfc.tech.IsoDep</tech>
    <tech>android.nfc.tech.NfcA</tech>
    <tech>android.nfc.tech.NfcB</tech>
    <tech>android.nfc.tech.NfcF</tech>
    <tech>android.nfc.tech.NfcV</tech>
    <tech>android.nfc.tech.Ndef</tech>
    <tech>android.nfc.tech.NdefFormatable</tech>
    <tech>android.nfc.tech.MifareClassic</tech>
    <tech>android.nfc.tech.MifareUltralight</tech>
</tech-list>

请帮帮我。

EN

回答 1

Stack Overflow用户

发布于 2013-08-02 03:08:30

tech-list需要一个标签来匹配列表中的所有项目。这在你的列表中是不可能的。最好试一试:

代码语言:javascript
复制
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
    <tech>android.nfc.tech.NfcA</tech>
</tech-list>
<tech-list>
    <tech>android.nfc.tech.NfcB</tech>
</tech-list>
<tech-list>
    <tech>android.nfc.tech.NfcF</tech>
</tech-list>
<tech-list>
    <tech>android.nfc.tech.NfcV</tech>
</tech-list>
<tech-list>
    <tech>android.nfc.tech.Ndef</tech>
</tech-list>
<tech-list>
    <tech>android.nfc.tech.NdefFormatable</tech>
</tech-list>
<tech-list>
    <tech>android.nfc.tech.MifareClassic</tech>
</tech-list>
<tech-list>
    <tech>android.nfc.tech.MifareUltralight</tech>
</tech-list>
</resources>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17989055

复制
相关文章

相似问题

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