我試圖在應用程序打開時閱讀NFC標籤(當我掃描標籤時自動打開),但似乎無法讀取有效內容。事實上,我似乎無法挑選標籤。我用另一個應用程序來讀取標籤的MIME類型和有效載荷 - 一切似乎都很好。Android NFC標籤閱讀。意圖始終爲空
道歉,如果這是一個明顯的 - 我已閱讀文件,並在發佈前檢查了各種其他來源,無濟於事。
我可以看到沒有錯誤,代碼編譯正常。 下面的代碼。 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>
你能顯示清單文件的內容嗎? –
當然。我剛剛編輯了這篇文章,並將其彈出到底部。 – Mike
我也無法獲得類型,但是我可以執行'intent.getAction()',如果有幫助的話。有了這個,我知道意圖不是無效的 - 對我來說,你的情況可能會有所不同。 –