• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MifareClassic类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中android.nfc.tech.MifareClassic的典型用法代码示例。如果您正苦于以下问题:Java MifareClassic类的具体用法?Java MifareClassic怎么用?Java MifareClassic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MifareClassic类属于android.nfc.tech包,在下文中一共展示了MifareClassic类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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");
    }
}
 
开发者ID:eliasson,项目名称:blekingebalance,代码行数:18,代码来源:Balance.java


示例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");

	}
 
开发者ID:mobilesec,项目名称:secure-element-gpdroid-nfc,代码行数:25,代码来源:MifareTest.java


示例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");

	}
 
开发者ID:mobilesec,项目名称:secure-element-gpdroid-nfc,代码行数:22,代码来源:MifareTest.java


示例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));
    }
}
 
开发者ID:pkern,项目名称:kitcard-reader,代码行数:20,代码来源:MainActivity.java


示例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);
}
 
开发者ID:pkern,项目名称:kitcard-reader,代码行数:19,代码来源:ReadCardTask.java


示例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));
    }
}
 
开发者ID:pkern,项目名称:kitcard-reader,代码行数:23,代码来源:ScanActivity.java


示例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();
	}
}
 
开发者ID:mchro,项目名称:RejsekortReader,代码行数:23,代码来源:DumpRaw.java


示例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();
   }
 
开发者ID:norenh,项目名称:RKFRead,代码行数:21,代码来源:RKFRead.java


示例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();
}
 
开发者ID:kwf2030,项目名称:NfcMifare,代码行数:23,代码来源:NfcMifareActivity.java


示例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);
    }
}
 
开发者ID:paulmd,项目名称:graboid,代码行数:20,代码来源:GrabActivity.java


示例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);
}
 
开发者ID:paulmd,项目名称:graboid,代码行数:25,代码来源:GrabActivity.java


示例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;
    }
}
 
开发者ID:paulmd,项目名称:graboid,代码行数:23,代码来源:MifareTask.java


示例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);
}
 
开发者ID:doctang,项目名称:android-basic-test,代码行数:22,代码来源:NfcTest.java


示例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;
	}
 
开发者ID:mobilesec,项目名称:secure-element-gpdroid-nfc,代码行数:32,代码来源:MifareTest.java


示例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();
}
 
开发者ID:mobilesec,项目名称:secure-element-gpdroid-nfc,代码行数:30,代码来源:MainActivity.java


示例16: MifareMad

import android.nfc.tech.MifareClassic; //导入依赖的package包/类
public MifareMad(MifareClassic card) throws IOException {
	this.card = card;

	if(!card.isConnected()) {
		try {
			card.connect();
			readMad();
		} finally {
			card.close();
		}
	} else {
		readMad();
	}
}
 
开发者ID:pkern,项目名称:kitcard-reader,代码行数:15,代码来源:MifareMad.java


示例17: readMad

import android.nfc.tech.MifareClassic; //导入依赖的package包/类
private boolean readMad() throws IOException {
	if(!card.authenticateSectorWithKeyA(0, MifareClassic.KEY_MIFARE_APPLICATION_DIRECTORY)) {
		Log.e("KITCard Reader", "Authentication with sector 0 failed");
		return false;
	}

	byte[] mad_descriptor = card.readBlock(card.sectorToBlock(0) + 3);
	byte general_purpose_byte = mad_descriptor[9];

	mad_version = general_purpose_byte & 3;
	multi_app = (general_purpose_byte & (1 << 7)) != 0;
	mad_available = (general_purpose_byte & (1 << 6)) != 0;
	publisher_sector = 0;

	if (mad_available) {
		byte[] mad = new byte[16*2];
		byte[] data = card.readBlock(card.sectorToBlock(0) + 1);
		System.arraycopy(data, 0, mad, 0, 16);
		data = card.readBlock(card.sectorToBlock(0) + 2);
		System.arraycopy(data, 0, mad, 16, 16);

		publisher_sector = mad[1] & 0x3f;
		for(int a = 2; a < mad.length; a += 2) {
			app_list.add(new MifareApp(mad[a], mad[a + 1]));
		}
	}

	return true;
}
 
开发者ID:pkern,项目名称:kitcard-reader,代码行数:30,代码来源:MifareMad.java


示例18: readBlocks

import android.nfc.tech.MifareClassic; //导入依赖的package包/类
private void readBlocks(MifareClassic mfc, int sectorIndex) throws IOException {
    int startBlockIndex = mfc.sectorToBlock(sectorIndex);
    for(int block = startBlockIndex; block < (startBlockIndex + 3); block++){
        final byte[] data = mfc.readBlock(block);
        mCard.addBlock(sectorIndex, (block%4), data);
    }
}
 
开发者ID:eliasson,项目名称:blekingebalance,代码行数:8,代码来源:ReadCardTask.java


示例19: randomBlockIndex

import android.nfc.tech.MifareClassic; //导入依赖的package包/类
private int randomBlockIndex(MifareClassic mfc) {
    int i = new Random().nextInt(mfc.getBlockCount());
    if (i == 0 || (i + 1) % 4 == 0) {
        return randomBlockIndex(mfc);
    }
    return i;
}
 
开发者ID:kwf2030,项目名称:NfcMifare,代码行数:8,代码来源:NfcMifareActivity.java


示例20: initializeNFC

import android.nfc.tech.MifareClassic; //导入依赖的package包/类
private void initializeNFC() {
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    mPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    mFilters = new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED) };
    mTechLists = new String[][] { new String[] { MifareClassic.class.getName() } };
}
 
开发者ID:paulmd,项目名称:graboid,代码行数:8,代码来源:GrabActivity.java



注:本文中的android.nfc.tech.MifareClassic类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Config类代码示例发布时间:2022-05-21
下一篇:
Java Encoder类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap