本文整理汇总了Java中android.nfc.tech.MifareClassic类的典型用法代码示例。如果您正苦于以下问题:Java MifareClassic类的具体用法?Java MifareClassic怎么用?Java MifareClassic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MifareClassic类属于android.nfc.tech包,在下文中一共展示了MifareClassic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupForegroundDispatch
import android.nfc.tech.MifareClassic; //导入依赖的package包/类
private void setupForegroundDispatch() {
try {
IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
filter.addDataType(MIME_TEXT_PLAIN);
mIntentFilters = new IntentFilter[] {
filter,
};
mTechLists = new String[][] { new String[] { MifareClassic.class.getName() } };
mPendingIntent = PendingIntent.getActivity(this, 0,
new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
}
catch(IntentFilter.MalformedMimeTypeException e) {
Log.e(LOG_TAG, "Malformed mime type");
}
}
示例2: authenticateA
import android.nfc.tech.MifareClassic; //导入依赖的package包/类
private void authenticateA(int sector, byte[] key) throws Exception {
if (mTag.authenticateSectorWithKeyA(sector, key)) {
return;
}
// if (mTag.authenticateSectorWithKeyB(sector,
// MifareClassic.KEY_DEFAULT)) {
// publishProgress("authenticated with default key");
// return;
// }
if (mTag.authenticateSectorWithKeyA(sector, MifareClassic.KEY_DEFAULT)) {
return;
}
byte[] inverted = new byte[key.length];
for (int i = 0; i < key.length; ++i)
inverted[i] = (byte) ~key[i];
if (mTag.authenticateSectorWithKeyA(sector, inverted)) {
log("authenticated with inverted sector key");
return;
}
throw new Exception("Authentication error");
}
示例3: authenticateB
import android.nfc.tech.MifareClassic; //导入依赖的package包/类
private void authenticateB(int sector, byte[] key) throws Exception {
if (mTag.authenticateSectorWithKeyB(sector, key)) {
return;
}
if (mTag.authenticateSectorWithKeyB(sector, MifareClassic.KEY_DEFAULT)) {
log("authenticated with default key");
return;
}
byte[] inverted = new byte[key.length];
for (int i = 0; i < key.length; ++i)
inverted[i] = (byte) ~key[i];
if (mTag.authenticateSectorWithKeyB(sector, inverted)) {
log("authenticated with inverted sector key");
return;
}
throw new Exception("Authentication error");
}
示例4: onCreate
import android.nfc.tech.MifareClassic; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
pendingIntent = PendingIntent.getActivity(this, 0,
new Intent("de.Ox539.kitcard.reader.TECH_DISCOVERED").addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
final IntentFilter intentFilter = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
intentFiltersArray = new IntentFilter[] { intentFilter };
techListsArray = new String[][] { new String[] { MifareClassic.class.getName() } };
NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE);
adapter = manager.getDefaultAdapter();
if (!adapter.isEnabled())
{
Toast.makeText(getApplicationContext(), getResources().getString(R.string.activate_nfc), Toast.LENGTH_LONG).show();
startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
}
}
示例5: doInBackground
import android.nfc.tech.MifareClassic; //导入依赖的package包/类
protected Pair<ReadCardResult, Wallet> doInBackground(Tag... tags) {
MifareClassic card = null;
try {
card = MifareClassic.get(tags[0]);
} catch (NullPointerException e) {
/* Error while reading card. This problem occurs on HTC devices from the ONE series with Android Lollipop (status of June 2015)
* Try to repair the tag.
*/
card = MifareClassic.get(MifareUtils.repairTag(tags[0]));
}
if(card == null)
return new Pair<ReadCardResult, Wallet>(null, null);
final Wallet wallet = new Wallet(card);
final ReadCardResult result = wallet.readCard();
return new Pair<ReadCardResult, Wallet>(result, wallet);
}
示例6: onCreate
import android.nfc.tech.MifareClassic; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
euroFormat = new EuroFormat();
pendingIntent = PendingIntent.getActivity(this, 0,
new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
final IntentFilter intentFilter = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
intentFiltersArray = new IntentFilter[] { intentFilter };
techListsArray = new String[][] { new String[] { MifareClassic.class.getName() } };
setContentView(R.layout.activity_scan);
resolveIntent(getIntent());
setTitle(getResources().getString(R.string.app_name));
NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE);
adapter = manager.getDefaultAdapter();
if (!adapter.isEnabled())
{
Toast.makeText(getApplicationContext(), getResources().getString(R.string.activate_nfc), Toast.LENGTH_LONG).show();
startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
}
}
示例7: resolveIntent
import android.nfc.tech.MifareClassic; //导入依赖的package包/类
void resolveIntent(Intent intent) {
// 1) Parse the intent and get the action that triggered this intent
String action = intent.getAction();
// 2) Check if it was triggered by a tag discovered interruption.
if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
// 3) Get an instance of the TAG from the NfcAdapter
Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
// 4) Get an instance of the Mifare classic card from this TAG
// intent
MifareClassic mfc = MifareClassic.get(tagFromIntent);
try {
mfc.connect();
mRKFCard = new RKFCard(mfc);
mCardContents = mRKFCard.readEntireCard();
txtRaw.setText(DataType.getHexString(mCardContents));
} catch (IOException e1) {
Log.e(TAG, e1.getLocalizedMessage(), e1);
}
Toast t = Toast.makeText(this, "Dump done!", Toast.LENGTH_SHORT);
t.show();
}
}
示例8: onResume
import android.nfc.tech.MifareClassic; //导入依赖的package包/类
@Override
public void onResume() {
super.onResume();
if(oldIntent != getIntent()) {
if(NfcAdapter.ACTION_TECH_DISCOVERED.equals(getIntent().getAction())) {
Tag tag = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);
mfc = null;
if(tag != null) {
mfc = MifareClassic.get(tag);
}
debugString = "";
if(null != mfc) {
readCard();
}
}
}
oldIntent = getIntent();
}
示例9: onCreate
import android.nfc.tech.MifareClassic; //导入依赖的package包/类
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.nfc);
mAdapter = NfcAdapter.getDefaultAdapter(this);
if (mAdapter == null) {
this.finish();
return;
}
mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
try {
filter.addDataType("*/*");
} catch (IntentFilter.MalformedMimeTypeException e) {
e.printStackTrace();
}
mIntentFilters = new IntentFilter[]{filter};
mTechList = new String[][]{new String[]{MifareClassic.class.getName()}};
initViews();
}
示例10: tagDetected
import android.nfc.tech.MifareClassic; //导入依赖的package包/类
private void tagDetected(Tag tag) {
MifareClassic mifareTag = MifareClassic.get(tag);
if (mifareTag == null) {
Toast.makeText(this, getString(R.string.err_unknown_card_type), Toast.LENGTH_SHORT).show();
return;
}
if (!mState.hasKeys()) {
Toast.makeText(this, R.string.tag_no_keys, Toast.LENGTH_SHORT).show();
} else if (mState.getState() == DomainState.State.CLEAN) {
Toast.makeText(this, R.string.tag_not_recording, Toast.LENGTH_SHORT).show();
} else if (mState.getState() == DomainState.State.LOADED) {
Toast.makeText(this, R.string.tag_not_replaying, Toast.LENGTH_SHORT).show();
} else if (mState.getState() == DomainState.State.RECORDING) {
readTag(mifareTag);
} else if (mState.getState() == DomainState.State.REPLAYING) {
writeTag(mifareTag);
}
}
示例11: writeTag
import android.nfc.tech.MifareClassic; //导入依赖的package包/类
public void writeTag(MifareClassic tag) {
// Test key compatibility
if (tag.getSectorCount() > mState.getKeys().getSectorCount()) {
Toast.makeText(this, R.string.err_to_few_keys, Toast.LENGTH_SHORT).show();
return;
}
// Get UID from tag and cmp with
byte[] newUID = tag.getTag().getId();
byte[] recordedUID = mState.getTag().getUID();
for (int i = 0; i < recordedUID.length; i++) {
if (newUID[i] != recordedUID[i]) {
Toast.makeText(this, R.string.err_wrong_uid, Toast.LENGTH_SHORT).show();
return;
}
}
// Create a retaining fragment and start the task
TaskFragment taskFragment = new TaskFragment();
WriteMifareTask writeTask = new WriteMifareTask(mState, taskFragment);
taskFragment.initialize(mState, writeTask, getString(R.string.write_tag_progress));
taskFragment.show(mFragmentManager, TASK_FRAGMENT_TAG);
writeTask.execute(tag);
}
示例12: doInBackground
import android.nfc.tech.MifareClassic; //导入依赖的package包/类
/**
* Must not refer to the activity from this or the processMifareTag
* override.
*/
@Override
protected Result doInBackground(MifareClassic... tagParam) {
if (tagParam == null || tagParam.length != 1 || tagParam[0].getType() != MifareClassic.TYPE_CLASSIC) {
mError = new Exception("Invalid tag type");
return null;
}
MifareClassic tag = tagParam[0];
try {
// Use publishProgress(0 .. 100) from the prcessMifareTag function
return processMifareTag(tag);
} catch (IOException e) {
mError = e;
return null;
}
}
示例13: onActivityCreated
import android.nfc.tech.MifareClassic; //导入依赖的package包/类
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
Intent intent = new Intent(getActivity(), getActivity().getClass());
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
mPendingIntent = PendingIntent.getActivity(getActivity(), 0, intent, 0);
mTechLists = new String[][] {new String[] {MifareClassic.class.getName()}};
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
try {
ndef.addDataType("*/*");
} catch (MalformedMimeTypeException e) {
throw new RuntimeException("fail", e);
}
mFilters = new IntentFilter[] {ndef};
setButtonVisibility(true);
}
示例14: doInBackground
import android.nfc.tech.MifareClassic; //导入依赖的package包/类
protected Void doInBackground(Void... v) {
if (mTag.getType() != MifareClassic.TYPE_CLASSIC
|| mTag.getSize() != MifareClassic.SIZE_1K) {
log("Invalid card type, only supporting Mifare Classic 1k");
return null;
}
log("Preparing tag...");
resetKeys();
mRunning = true;
for (int i = 0; i < nRuns; ++i) {
if (isCancelled())
break;
runSingle(i);
}
try {
mTestLog.writeToFile("/storage/sdcard0/mifare_test.log");
} catch (IOException e) {
log("Error writing to log file");
}
log("Restoring default keys");
resetKeys();
mRunning = false;
return null;
}
示例15: onResume
import android.nfc.tech.MifareClassic; //导入依赖的package包/类
@Override
protected void onResume() {
super.onResume();
NfcManager nMan = (NfcManager) this
.getSystemService(Context.NFC_SERVICE);
mNfcAdapter = nMan.getDefaultAdapter();
PendingIntent pi = createPendingResult(PENDING_INTENT_TECH_DISCOVERED,
new Intent(), 0);
mNfcAdapter
.enableForegroundDispatch(
this,
pi,
new IntentFilter[] { new IntentFilter(
NfcAdapter.ACTION_TECH_DISCOVERED) },
new String[][] {
new String[] { android.nfc.tech.MifareClassic.class
.getName() },
new String[] { android.nfc.tech.IsoDep.class
.getName() } });
if (mTerminal == null) {
mTerminal = // new OpenMobileAPITerminal(this, this);
NfcTerminal.getInstance(this);
}
mTCPConnection = new TCPConnection(this, this);
Thread td = new Thread(mTCPConnection);
td.start();
}