Permalink
Cannot retrieve contributors at this time
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?
6001CEM_BF_ANEA/app/src/main/java/com/mobile/emvpay/PaymentActivity.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
94 lines (76 sloc)
2.56 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} | |
} |