本文整理汇总了Java中android.nfc.tech.IsoDep.connect方法的典型用法代码示例。如果您正苦于以下问题:Java IsoDep.connect方法的具体用法?Java IsoDep.connect怎么用?Java IsoDep.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.nfc.tech.IsoDep
的用法示例。
在下文中一共展示了IsoDep.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTagDiscovered
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
@Override
public void onTagDiscovered(Tag tag) {
Log.d(TAG, "onTagDiscovered: " + tag);
final long startTime = System.currentTimeMillis();
long duration;
try {
IsoDep isoDep = IsoDep.get(tag);
isoDep.connect();
onTagDiscovered(tag, isoDep, true);
} catch (Throwable e) {
Log.e(TAG, "Exception in onTagDiscovered", e);
getPaymentRequestDelegate().onPaymentError(e.getMessage());
}
}
示例2: create
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
/**
* Creates a transceiver for the specified tag.
* @return null is returned if a transceiver could not be created
*/
public static Transceiver create(Logger logger, Tag tag)
{
IsoDep isoDep = IsoDep.get(tag);
if (null == isoDep)
{
logger.warn(TAG, "Unable to create IsoDep for NFC tag: " + StringUtil.join(tag.getTechList(), ", "));
return null;
}
logger.info(TAG, "Connnecting to ISO-DEP: " + isoDep.isConnected());
try
{
isoDep.connect();
isoDep.setTimeout(30000);
return new Transceiver(logger, isoDep);
}
catch (Exception ex)
{
logger.error(TAG, "Unable to connect to ISO-DEP", ex);
return null;
}
}
示例3: get
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
public static AndroidCard get(Tag tag) throws IOException {
IsoDep card = IsoDep.get(tag);
if(card != null) {
/* Workaround for the Samsung Galaxy S5 (since the
* first connection always hangs on transceive).
* TODO: This could be improved if we could identify
* Samsung Galaxy S5 devices
*/
card.connect();
card.close();
return new AndroidCard(card);
} else {
return null;
}
}
示例4: get
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
public static AndroidCard get(Tag tag) throws IOException {
IsoDep card = IsoDep.get(tag);
/* Workaround for the Samsung Galaxy S5 (since the
* first connection always hangs on transceive).
* TODO: This could be improved if we could identify
* Samsung Galaxy S5 devices
*/
card.connect();
card.close();
if(card != null) {
return new AndroidCard(card);
} else {
return null;
}
}
示例5: softResetNFC
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
private void softResetNFC(final Tag tag) {
try {
Log.d(TAG, "try soft reset");
IsoDep isoDep = IsoDep.get(tag);
isoDep.close();
isoDep.connect();
Log.d(TAG, "soft reset successful");
onTagDiscovered(tag, isoDep, false);
} catch (Throwable e) {
Log.d(TAG, "Soft reset failed", e);
}
}
示例6: readCardData
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
private TravelCard readCardData(Intent intent) {
Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
IsoDep isoDep = IsoDep.get(tagFromIntent);
try {
isoDep.connect();
return CardOperations.readTravelCardData(isoDep);
} catch (IOException ioErr) {
Toast err = Toast.makeText(this, ioErr.getMessage(), Toast.LENGTH_LONG);
err.show();
return new TravelCard(TravelCard.STATUS_NO_HSL_CARD);
}
}
示例7: U2F_V2
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
public U2F_V2(IsoDep tag) throws IOException, APDUError {
this.tag = tag;
tag.setTimeout(5000);
tag.connect();
try {
send(SELECT_COMMAND);
} catch (APDUError e) {
if(e.getCode() == 0x6a82) {
send(SELECT_COMMAND_YUBICO);
} else {
throw e;
}
}
}
示例8: handleIntent
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
private void handleIntent(Intent intent) {
final String action = intent.getAction();
if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action) || NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) {
Log.d(TAG, "TECH_DISCOVERED");
final Parcelable tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
final IsoDep iso = IsoDep.get((Tag) tag);
try {
iso.connect();
doGetApps(iso);
doSelectPICC(iso);
doGetFileIDs(iso);
final String expiry = doGetFile(iso, (byte)0x02, (byte)0x0A);
final String idNumber = doGetFile(iso, (byte)0x03, (byte)0x09);
fillFields(idNumber, expiry);
iso.close();
} catch (IOException io) {
Log.e(TAG, "Error communicating: " + io.toString());
}
}
}
示例9: transceiveApdu
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
static byte[] transceiveApdu(IsoDep tag, byte[] cmd) {
if (tag != null) {
try {
if (!tag.isConnected()) {
tag.connect();
tag.setTimeout(10000);
}
return tag.transceive(cmd);
} catch (Exception e) {
}
}
return null;
}
示例10: onHandleIntent
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
if(BuildConfig.DEBUG) {
Log.i(this.getClass().getName(), "CardReaderService started");
}
// get an instance of the nfc tag to communicate
IsoDep isodep = IsoDep.get((Tag)intent.getParcelableExtra(NfcAdapter.EXTRA_TAG));
if(isodep != null) {
try {
// connect to the nfc tag
isodep.connect();
// select application which contains the credit and last transaction
resultOk = isodep.transceive(selectAid);
if (resultOk[0] == 0) {
// get the credit
creditBytes = isodep.transceive(creditPayload);
// get the last transaction
lastTransactionBytes = isodep.transceive(transactionPayload);
} else {
if (BuildConfig.DEBUG) {
Log.w(this.getClass().getName(), "Wrong result: " + arrayToString(resultOk));
}
}
isodep.close();
} catch (IOException e) {
// nfc-card wasn't properly connected and thus wasn't read
if (BuildConfig.DEBUG) {
Log.e(this.getClass().getName(), e.getMessage());
}
statusCode = STATUS_UNKNOWN_ERROR;
}
}else{
// i think this gets executed if an unsupported nfc-card gets connected
// however i'm unable to test this because i have no other card to test it
statusCode = STATUS_UNKNOWN_NFC_CARD_ERROR;
}
// send data back to the MainActivity
sendBroadcast();
}
示例11: IsoDepApduInterface
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
public IsoDepApduInterface(final IsoDep tag) throws IOException {
this.tag = tag;
tag.connect();
tag.setTimeout(TAG_TIMEOUT);
}
示例12: readTransactionLog
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
private void readTransactionLog(Tag tag) {
IsoDep card = IsoDep.get(tag);
if (card == null) {
Snackbar.make(findViewById(R.id.coordinatorLayout),
R.string.error_card_incompatible,
Snackbar.LENGTH_SHORT).show();
return;
}
try {
byte[] reset_card = new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x00, (byte) 0x00, (byte) 0x00};
byte[] select_vdv = new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x04,
(byte) 0x00, (byte) 0x0C, (byte) 0xD2, (byte) 0x76, (byte) 0x00, (byte) 0x01,
(byte) 0x35, (byte) 0x4B, (byte) 0x41, (byte) 0x4E, (byte) 0x4D, (byte) 0x30,
(byte) 0x31, (byte) 0x00, (byte) 0x00};
card.connect();
card.transceive(reset_card);
byte[] response = card.transceive(select_vdv);
if (response[response.length - 2] == (byte) 0x90 && response[response.length - 1] == (byte) 0x00) {
ArrayList<BaseCard> applicationLog = new ArrayList<>();
for (int i = 1; i < 11; i++) {
byte[] byteResponse = card.transceive(new byte[]{(byte) 0x00, (byte) 0xCA,
(byte) 0x01, (byte) 0xF0, (byte) 0x02, (byte) 0xE5, (byte) i, (byte) 0x00});
if (byteResponse.length > 2) {
if (byteResponse[0] == (byte) 0xF1) {
JourneyCard tc = new JourneyCard(byteResponse);
int stationID = tc.transactionData.location.getID().intValue();
stationProvider.getStation(stationID);
applicationLog.add(tc);
} else if (byteResponse[0] == (byte) 0xF6) {
TicketActivationCard ta = new TicketActivationCard(byteResponse);
applicationLog.add(ta);
} else if (byteResponse[0] == (byte) 0xF7) {
ApplicationActivationCard aa = new ApplicationActivationCard(byteResponse);
applicationLog.add(aa);
}
}
}
applicationLogFragment.setApplicationLog(applicationLog);
card.transceive(new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x00, (byte) 0x00, (byte) 0x00});
card.transceive(new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x04,
(byte) 0x00, (byte) 0x0C, (byte) 0xD2, (byte) 0x76, (byte) 0x00, (byte) 0x01,
(byte) 0x35, (byte) 0x4B, (byte) 0x41, (byte) 0x4E, (byte) 0x4D, (byte) 0x30,
(byte) 0x31, (byte) 0x00, (byte) 0x00});
ArrayList<BaseCard> applicationDetailEntries = new ArrayList<>();
applicationDetailEntries.add(new ApplicationDetailsCard(card.transceive(new byte[]{(byte) 0x00, (byte) 0xCA,
(byte) 0x01, (byte) 0xF0, (byte) 0x02, (byte) 0xE2, (byte) 0x00, (byte) 0x00})));
applicationDetailFragment.setApplicationDetails(applicationDetailEntries);
card.close();
Snackbar.make(findViewById(R.id.coordinatorLayout),
R.string.info_read_card_successful,
Snackbar.LENGTH_SHORT).show();
} else {
Snackbar.make(findViewById(R.id.coordinatorLayout),
R.string.error_card_no_eticket,
Snackbar.LENGTH_SHORT).show();
}
} catch (IOException e) {
Snackbar.make(findViewById(R.id.coordinatorLayout),
R.string.error_card_communication,
Snackbar.LENGTH_SHORT).show();
e.printStackTrace();
}
}
示例13: readIntent
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
@TargetApi(10)
public static CreditCardNfcResult readIntent(Intent paramIntent)
throws IOException, UnsupportedTagException, TagReadTimeoutException, TagReadException
{
IsoDep localIsoDep = IsoDep.get((Tag)paramIntent.getParcelableExtra("android.nfc.extra.TAG"));
if (localIsoDep == null) {
throw new UnsupportedTagException();
}
try
{
localIsoDep.connect();
localIsoDep.setTimeout(NFC_TIMEOUT_MS);
String[] arrayOfString1 = ApduUtil.SUPPORTED_PSE_AIDS;
int i = arrayOfString1.length;
for (int j = 0; j < i; j++)
{
ResponseApdu localResponseApdu = new ResponseApdu(transceive(localIsoDep, ApduUtil.buildSelectCommand(arrayOfString1[j]).command));
CreditCardNfcResult localCreditCardNfcResult2;
if (ApduUtil.matchesStatus(localResponseApdu, ResponseApdu.SUCCESS_SW))
{
TlvDatum localTlvDatum = TlvUtil.findNestedTlv(TlvParser.parseTlv(localResponseApdu), TlvUtil.APPLICATION_IDENTIFIER_TAG);
if (localTlvDatum != null) {
localCreditCardNfcResult2 = aidRead(localIsoDep, TlvUtil.getValue(localTlvDatum));
}
}
for (CreditCardNfcResult localCreditCardNfcResult1 = localCreditCardNfcResult2; localCreditCardNfcResult1 != null; localCreditCardNfcResult1 = null) {
return localCreditCardNfcResult1;
}
}
String[] arrayOfString2 = ApduUtil.SUPPORTED_AIDS;
int k = arrayOfString2.length;
for (int m = 0; m < k; m++)
{
CreditCardNfcResult localCreditCardNfcResult3 = aidRead(localIsoDep, arrayOfString2[m]);
if (localCreditCardNfcResult3 != null) {
return localCreditCardNfcResult3;
}
}
throw new TagReadException();
}
finally
{
localIsoDep.close();
}
}
示例14: YkneoBitcoinNfc
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
public YkneoBitcoinNfc(IsoDep nfc) throws IOException {
this.nfc = nfc;
nfc.connect();
select();
}
示例15: onNewIntent
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
@Override
protected void onNewIntent(Intent intent) {
Log.d(TAG, "Intent: " + intent);
setIntent(intent);
try {
if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())
|| NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent
.getAction())) {
Tag tagFromIntent = intent
.getParcelableExtra(NfcAdapter.EXTRA_TAG);
messageText.setText("Found NFC tag: ");
Log.d(TAG, "Suported techs: ");
for (String tech : tagFromIntent.getTechList()) {
Log.d(TAG, "\t" + tech);
messageText.append(tech.replaceAll("android.nfc.", "")
+ " ");
}
messageText.append("\n");
IsoDep tag = IsoDep.get(tagFromIntent);
if (tag == null) {
Log.w(TAG, "Not an IsoDep tag: " + tagFromIntent);
return;
}
tag.connect();
msc = new MuscleCard(tag);
try {
msc.select();
messageText.append("Found MuscleCard");
nfcSignButton.setEnabled(true);
} finally {
if (tag != null) {
tag.close();
}
}
}
} catch (Exception e) {
Log.e(TAG, "Error: " + e.getMessage(), e);
Toast.makeText(this, "Error: " + e.getMessage(), Toast.LENGTH_LONG)
.show();
}
}