Android NFC-无法检测标签
未调用onNewIntent(Intent-Intent)方法 我正在尝试的代码是Android NFC-无法检测标签,android,nfc,nfc-p2p,open-nfc,Android,Nfc,Nfc P2p,Open Nfc,未调用onNewIntent(Intent-Intent)方法 我正在尝试的代码是 public class NfcTagDetector extends Activity{ private NfcAdapter mNfcAdapter; private PendingIntent pendingIntent; private IntentFilter[] intentFiltersArray; @Override protected void onCreate(Bundle savedI
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
<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文件为
<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>
android.nfc.tech.IsoDep
android.nfc.tech.NfcA
android.nfc.tech.NfcB
android.nfc.tech.NfcF
android.nfc.tech.NfcV
android.nfc.tech.Ndef
android.nfc.tech.n可验证
android.nfc.tech.MifareClassic
android.nfc.tech.MifareUltralight
请帮助……技术列表需要一个标签来匹配列表中的所有项目。这在你的清单上是不可能的。最好尝试:
<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>
android.nfc.tech.NfcA
android.nfc.tech.NfcB
android.nfc.tech.NfcF
android.nfc.tech.NfcV
android.nfc.tech.Ndef
android.nfc.tech.n可验证
android.nfc.tech.MifareClassic
android.nfc.tech.MifareUltralight
您要检测哪种类型的标签?我想问题可能在于你的“花生”是的,你是对的,你知道。。问题出在我的设备上。我在试三星S II,它的NFC有缺陷。。现在我试过Nexus,一切都正常了是的,你说得对。。最大的问题是,我在一个有缺陷的支持NFC的设备上测试代码。。谢谢nyways NFC的家伙+1.谢谢你的帮助。。