Skip to content
Permalink
e8b09da827
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
94 lines (76 sloc) 2.56 KB
package com.mobile.emvpay;
import android.app.PendingIntent;
import android.content.Intent;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.IsoDep;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import java.io.IOException;
public class PaymentActivity extends AppCompatActivity {
private NfcAdapter nfcAdapter;
private PendingIntent pendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.payment_activity);
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
}
@Override
protected void onResume() {
super.onResume();
if (nfcAdapter != null) {
nfcAdapter.enableForegroundDispatch(this, pendingIntent, null, null);
}
}
@Override
protected void onPause() {
super.onPause();
if (nfcAdapter != null) {
nfcAdapter.disableForegroundDispatch(this);
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
if (tag != null) {
IsoDep isoDep = IsoDep.get(tag);
if (isoDep != null) {
// Process the payment card with IsoDep
processPaymentCard(isoDep);
}
}
}
private void processPaymentCard(IsoDep isoDep) {
try {
isoDep.connect();
// PPSE command
byte[] ppseCommand = {
// Your PPSE command bytes
};
byte[] ppseResponse = isoDep.transceive(ppseCommand);
// Parse the response and extract AID
// SELECT AID command
byte[] selectAidCommand = {
// Your SELECT AID command bytes with the extracted AID
};
byte[] selectAidResponse = isoDep.transceive(selectAidCommand);
// GPO command
byte[] gpoCommand = {
// Your GPO command bytes
};
byte[] gpoResponse = isoDep.transceive(gpoCommand);
// Process the GPO response
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
isoDep.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}