本文整理汇总了Java中android.nfc.tech.IsoDep类的典型用法代码示例。如果您正苦于以下问题:Java IsoDep类的具体用法?Java IsoDep怎么用?Java IsoDep使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IsoDep类属于android.nfc.tech包,在下文中一共展示了IsoDep类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTagDiscovered
import android.nfc.tech.IsoDep; //导入依赖的package包/类
@Override
public void onTagDiscovered(final Tag tag) {
Log.d(TAG, "Tag found: " + tag.toString());
Log.d(TAG, "Id: " + HexStrings.toHexString(tag.getId()));
for (String tech: tag.getTechList()) {
Log.d(TAG, "Tech: " + tech);
}
if (Arrays.asList(tag.getTechList()).contains("android.nfc.tech.IsoDep")) {
IsoDepApduInterface apduInterface;
try {
apduInterface = new IsoDepApduInterface(IsoDep.get(tag));
} catch (IOException e) {
fail(e.getMessage());
e.printStackTrace();
return;
}
dispatchLoadTask(apduInterface);
}
}
示例2: transceiveDER
import android.nfc.tech.IsoDep; //导入依赖的package包/类
private DERObject transceiveDER(IsoDep isoDep, DERObject input, boolean needsSelectAidApdu) throws IOException {
final long startTimeTransceive = System.currentTimeMillis();
final byte[] derPayload = input.serializeToDER();
byte[] derResponse;
Log.d(TAG, "transceiveDER - start - send derPayload length=" + derPayload.length + " byte");
derResponse = assembleFragment(isoDep, derPayload, needsSelectAidApdu);
derResponse = keepAliveLoop(isoDep, derResponse);
derResponse = concatNextResponseBytes(isoDep, derResponse);
DERObject result = DERParser.parseDER(derResponse);
long duration = System.currentTimeMillis() - startTimeTransceive;
Log.d(TAG, "transceiveDER - end - " +
"took " + duration + " ms - " +
"received length=" + result.getPayload().length + " byte");
return result;
}
示例3: assembleFragment
import android.nfc.tech.IsoDep; //导入依赖的package包/类
private byte[] assembleFragment(IsoDep isoDep, byte[] derPayload, boolean needsSelectAidApdu) throws IOException {
int fragmentByte = 0;
byte[] derResponse = new byte[0];
while (fragmentByte < derPayload.length) {
byte[] fragment = new byte[0];
if (needsSelectAidApdu) {
Log.d(TAG, "transceiveDER - select Aid Apdu");
byte[] retval = isoDep.transceive(NFCUtils.createSelectAidApdu(NFCUtils.AID_ANDROID));
Log.d(TAG, "transceiveDER - select Aid Apdu OK! "+retval.length);
if(NFCUtils.isKeepAlive(retval)) {
needsSelectAidApdu = false;
}
}
int endLength = Math.min(derPayload.length, fragmentByte + NFCUtils.DEFAULT_MAX_FRAGMENT_SIZE);
byte[] fragmentPart = Arrays.copyOfRange(derPayload, fragmentByte, endLength);
fragment = ClientUtils.concatBytes(fragment, fragmentPart);
Log.d(TAG, "transceiveDER - about to send fragment size: " + fragment.length);
derResponse = isoDep.transceive(fragment);
Log.d(TAG, "transceiveDER - received payload: " + Arrays.toString(derResponse));
fragmentByte += fragment.length;
}
return derResponse;
}
示例4: 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());
}
}
示例5: enableDispatch
import android.nfc.tech.IsoDep; //导入依赖的package包/类
/**
* Activate NFC dispacher to read NFC Card Set the most important priority to the foreground application
*/
public static void enableDispatch(Activity activity) {
if (isNfcEnabled(activity)) {
NfcAdapter adapter = getNfcAdapter(activity);
PendingIntent pendingIntent = PendingIntent.getActivity(
activity,
0,
new Intent(activity, activity.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
0);
IntentFilter[] intentFilter = new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED) };
String[][] techList = new String[][] { { IsoDep.class.getName() } };
adapter.enableForegroundDispatch(activity, pendingIntent, intentFilter, techList);
}
}
示例6: 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;
}
}
示例7: readRecord
import android.nfc.tech.IsoDep; //导入依赖的package包/类
@TargetApi(10)
private static CreditCardNfcResult readRecord(IsoDep paramIsoDep, byte paramByte1, byte paramByte2)
throws IOException, TagReadTimeoutException
{
ResponseApdu localResponseApdu = new ResponseApdu(transceive(paramIsoDep, ApduUtil.buildReadCommand(paramByte1, paramByte2).command));
if (ApduUtil.matchesStatus(localResponseApdu, ResponseApdu.WRONG_LENGTH_LE)) {
localResponseApdu = new ResponseApdu(transceive(paramIsoDep, ApduUtil.buildReadCommand(paramByte1, paramByte2, localResponseApdu.statusWord2).command));
}
if (ApduUtil.matchesStatus(localResponseApdu, ResponseApdu.SUCCESS_SW))
{
CreditCardNfcResult localCreditCardNfcResult = TlvUtil.parseCreditCardInfoFromTlv(TlvParser.parseTlv(localResponseApdu));
if (localCreditCardNfcResult != null) {
return localCreditCardNfcResult;
}
}
return null;
}
示例8: onChallengeReceived
import android.nfc.tech.IsoDep; //导入依赖的package包/类
private void onChallengeReceived() {
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(getActivity());
if (adapter == null) {
Toast.makeText(getActivity(), R.string.no_nfc, Toast.LENGTH_LONG).show();
} else if (adapter.isEnabled()) {
Intent intent = getActivity().getIntent();
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent tagIntent = PendingIntent.getActivity(getActivity(), 0, intent, 0);
IntentFilter iso = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
((MainActivity) getActivity()).setOnNFCListener(SignFragment.this);
adapter.enableForegroundDispatch(getActivity(), tagIntent, new IntentFilter[]{iso},
new String[][]{new String[]{IsoDep.class.getName()}});
getView().findViewById(R.id.progressBar).setVisibility(View.INVISIBLE);
((TextView) getView().findViewById(R.id.status_text)).setText(R.string.swipe);
} else {
Toast.makeText(getActivity(), R.string.nfc_disabled, Toast.LENGTH_LONG).show();
}
}
示例9: onChallengeReceived
import android.nfc.tech.IsoDep; //导入依赖的package包/类
private void onChallengeReceived() {
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(getActivity());
if (adapter == null) {
Toast.makeText(getActivity(), R.string.no_nfc, Toast.LENGTH_LONG).show();
} else if (adapter.isEnabled()) {
Intent intent = getActivity().getIntent();
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent tagIntent = PendingIntent.getActivity(getActivity(), 0, intent, 0);
IntentFilter iso = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
((MainActivity) getActivity()).setOnNFCListener(EnrollFragment.this);
adapter.enableForegroundDispatch(getActivity(), tagIntent, new IntentFilter[]{iso},
new String[][]{new String[]{IsoDep.class.getName()}});
getView().findViewById(R.id.progressBar).setVisibility(View.INVISIBLE);
((TextView) getView().findViewById(R.id.status_text)).setText(R.string.swipe);
} else {
Toast.makeText(getActivity(), R.string.nfc_disabled, Toast.LENGTH_LONG).show();
}
}
示例10: doTransceiveUTF8
import android.nfc.tech.IsoDep; //导入依赖的package包/类
private String doTransceiveUTF8(IsoDep iso, byte[] command) throws IOException {
final byte[] ret = iso.transceive(command);
Log.d(TAG, "Sent: " + ByteArrayToHexString(command) + "\nRecv: " + ByteArrayToHexString(ret));
final StringBuffer buffer = new StringBuffer();
for(int i = 1; i < ret.length; i++) {
buffer.append((char)ret[i]);
}
final String retStr = buffer.toString();
Log.d(TAG, "UTF-8: " + retStr);
return retStr;
}
示例11: 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;
}
}
示例12: doInBackground
import android.nfc.tech.IsoDep; //导入依赖的package包/类
@Override
protected String doInBackground(Tag... params) {
Tag tag = params[0];
tagCommunicator = IsoDep.get(tag);
try {
tagCommunicator.connect();
tagCommunicator.setTimeout(5000);
if (tagCommunicator.isConnected()) {
readCard();
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例13: 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;
}
}
示例14: onTagDiscovered
import android.nfc.tech.IsoDep; //导入依赖的package包/类
@Override
public void onTagDiscovered(Tag tag) {
doTapFeedback();
clearImage();
// maybe clear console or show separator, depends on settings
if (mAutoClear) {
clearMessages();
} else {
addMessageSeparator();
}
// get IsoDep handle and run xcvr thread
IsoDep isoDep = IsoDep.get(tag);
if (isoDep == null) {
onError(getString(R.string.wrong_tag_err));
} else {
ReaderXcvr xcvr = new PaymentReaderXcvr(isoDep, "", this, TEST_MODE_EMV_READ);
new Thread(xcvr).start();
}
}
示例15: onTagDiscovered
import android.nfc.tech.IsoDep; //导入依赖的package包/类
@Override
public void onTagDiscovered(Tag tag) {
doTapFeedback();
clearImage();
// maybe clear console or show separator, depends on settings
if (mAutoClear) {
clearMessages();
} else {
// two separators between taps/discoveries
addMessageSeparator();
addMessageSeparator();
}
// get IsoDep handle and run xcvr thread
IsoDep isoDep = IsoDep.get(tag);
if (isoDep == null) {
onError(getString(R.string.wrong_tag_err));
} else {
List<SmartcardApp> memberApps = mGrpToMembersMap.get(mSelectedGrpPos);
new Thread(new BatchReaderXcvr(isoDep, memberApps, this)).start();
}
}