0

我正在尝试在打开应用程序时读取 NFC 标签(扫描标签时自动打开),但我似乎无法读取有效负载。事实上,我似乎根本无法拿起标签。我已经使用另一个应用程序来读取标签的 mime 类型和有效负载 - 一切似乎都很好。

抱歉,如果这是一个明显的问题 - 我已经阅读了文档并在发布之前检查了各种其他来源,但无济于事。

我看不到任何错误,并且代码编译得很好。代码如下。Logcat 显示:

08-30 20:15:50.248: E/Activity...(3703): Hello world. Intent Type: null

package com.spotsofmagic.spotsofmagic;

import android.app.Activity;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.widget.TextView;


public class MainActivity extends Activity implements OnClickListener {
    private static final String TAG = "Activity...";
    private NfcAdapter mAdapter;
    private TextView mTextView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);

        // grab our NFC Adapter
        mAdapter = NfcAdapter.getDefaultAdapter(this);

        // TextView that we'll use to output messages to screen
        mTextView = (TextView)findViewById(R.id.text_view);

        displayMessage("Loading payload...");
        // see if app was started from a tag and show game console
        Intent intent = getIntent();


        Log.e(TAG, "Hello world.  Intent Type: "+ intent.getType());

清单文件;

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14" />

<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >

    <activity
        android:name=".MainActivity"
        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=".CardActivity"
        android:label="@string/app_name" >

        <!-- Handle a collectable card NDEF record -->
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
            <data android:mimeType="application/vnd.spotsofmagic.bluetoothon"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
     </activity>

</application>

4

1 回答 1

1

NFC 意图过滤器适用于 CardActivity,而不适用于 MainActivity。所以我希望问题出在 CardActivity 中。

于 2012-08-30T20:37:17.920 回答