Android 使用NFC监听信用卡信息

Android 使用NFC监听信用卡信息,android,nfc,Android,Nfc,是否有任何关于如何创建示例应用程序监听信用卡状态的工作示例 我从Android示例中尝试了这段代码,但在扫描卡时什么也没发生(NFC正在工作,我听到了嘟嘟声) 我的清单文件可能有问题: 看一看。我简要介绍了您需要收听的NFC标签类型,以便对非接触式EMV卡的存在作出反应。该代码使用Triangle.io的API在检测到卡后提取卡信息,但您可以根据需要非常轻松地更改该部分。请查看。我简要介绍了您需要收听的NFC标签类型,以便对非接触式EMV卡的存在作出反应。代码使用Triangle.io的

是否有任何关于如何创建示例应用程序监听信用卡状态的工作示例

我从Android示例中尝试了这段代码,但在扫描卡时什么也没发生(
NFC
正在工作,我听到了嘟嘟声)

我的
清单
文件可能有问题:



看一看。我简要介绍了您需要收听的NFC标签类型,以便对非接触式EMV卡的存在作出反应。该代码使用Triangle.io的API在检测到卡后提取卡信息,但您可以根据需要非常轻松地更改该部分。

请查看。我简要介绍了您需要收听的NFC标签类型,以便对非接触式EMV卡的存在作出反应。代码使用Triangle.io的API在检测到卡后提取卡信息,但您可以非常轻松地根据需要更改该部分。

这里有一个很好的答案:不是真的,所有答案都链接到SDK,我想创建自己的如果您指的是符合EMV的信用卡,你可能想让你的应用程序对IsoDep技术敏感,而不是NfcF(EMV信用卡肯定不会使用NfcF)。另外,你的信用卡通常不会包含NDEF消息,所以跳过那些意图过滤器。但我认为问题是,操作始终是主要的…当然它是主要的。。。在
onResume()
中。清单中的意图过滤器未真正设置为在检测到信用卡时启动应用程序(NDEF_发现的意图和回退标记_发现的意图很可能都不会触发。如果要接收前台分派意图,则必须坚持
onNewIntent()
。无论如何,你想对通过TECH
IsoDep
发现的TECH\u保持敏感(无论是舱单还是前台调度)。这里有一个很好的答案:不是真的,所有答案都链接到SDK,我想创建我自己的。如果你指的是符合EMV的信用卡,你可能想让你的应用程序对IsoDep TECH敏感,而不是NfcF(这当然不是EMV信用卡使用的)。此外,您的信用卡通常不会包含NDEF消息,因此请跳过这些意图过滤器。但我认为问题是,操作始终是主要的…当然是主要的…在
onResume()中
。清单中的目的过滤器未真正设置为在检测到信用卡时启动应用程序(NDEF\u发现的目的和回退标记\u发现的目的很可能都不会触发。如果要接收前台分派目的,则必须坚持
onNewIntent()
。无论如何,您希望对通过TECH
IsoDep发现的技术保持敏感(无论是舱单还是前台调度)。
 public class MainActivity extends Activity {

private NfcAdapter mAdapter;
private PendingIntent mPendingIntent;
private IntentFilter[] mFilters;
private String[][] mTechLists;
private TextView mText;
private int mCount = 0;

@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    setContentView(R.layout.activity_main);

    mAdapter = NfcAdapter.getDefaultAdapter(this);

    mPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    try {
        ndef.addDataType("*/*");
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("fail", e);
    }
    mFilters = new IntentFilter[] {
            ndef,
    };

    mTechLists = new String[][] { new String[] { NfcF.class.getName() } };
}

@Override
public void onResume() {
    super.onResume();
    mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);

    String action = getIntent().getAction(); //allways MAIN, even after scanning a card
    Parcelable[] msg1 = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); //allways null
    Parcelable[] msg2 = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_TAG); //allways null
}

@Override
public void onNewIntent(Intent intent) {
    Log.i("Foreground dispatch", "Discovered tag with intent: " + intent);
    mText.setText("Discovered tag " + ++mCount + " with intent: " + intent);

}
@Override
public void onPause() {
    super.onPause();
    mAdapter.disableForegroundDispatch(this);
}

}
<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.NFC" />

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="pl.aprilapps.nfcreader.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.nfc.action.TAG_DISCOVERED" />

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

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

            <data android:mimeType="text/plain" />
        </intent-filter>
    </activity>
</application>