我有一個類,它創建了NFC和兩個活動的連接。他們都創建該類的對象,以便他們可以連接到NFC。 早些時候它以某種方式工作,但現在我有問題 - 即使在第一個活動上,我的應用程序也不會對NewIntent執行任何操作。取而代之的是,我可以從名爲「標籤」(Nexus S)的內置應用程序中看到「收集到新標籤」。「收集新標籤」而不是閱讀應用程序標籤 - NFC android
我該怎麼辦?
類:
public NFCForegroundUtil(Activity activity)
{
super();
this.activity = activity;
mAdapter = NfcAdapter.getDefaultAdapter(activity
.getApplicationContext());
mPendingIntent = PendingIntent.getActivity(activity, 0, new Intent(
activity, activity.getClass())
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
IntentFilter ndef2 = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
IntentFilter ndef3 = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
try
{
ndef2.addDataType("*/*");
}
catch (MalformedMimeTypeException e)
{
throw new RuntimeException("fail", e);
}
mFilters = new IntentFilter[] {ndef, ndef2, ndef3 };
mTechLists = new String[][] { new String[] {
// android.nfc.tech.NfcV.class.getName(),
android.nfc.tech.NfcA.class.getName(),
android.nfc.tech.IsoDep.class.getName() } };
mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);
}
活動1:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
nfcForegroundUtil = new NFCForegroundUtil(this);
}
@Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
Intent i = new Intent(this, NfcDisplayLabelActivity2.class);
startActivity(i);
}
那麼,你是如何使它正常工作的? –
如果您仍然有問題,請查看我的答案。 – MagicSeth
這個答案中確實沒有任何有用的數據。簡單地說,「哦,我更正了我的應用程序,現在它的工作原理」並沒有告訴社區關於該應用程序被更正以及您最初做錯了什麼的任何事情。 – jwir3