android.nfc.tech.NfcF Java Examples

The following examples show how to use android.nfc.tech.NfcF. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Tag.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private static HashMap<String, Integer> getTechStringToCodeMap() {
    HashMap<String, Integer> techStringToCodeMap = new HashMap<String, Integer>();

    techStringToCodeMap.put(IsoDep.class.getName(), TagTechnology.ISO_DEP);
    techStringToCodeMap.put(MifareClassic.class.getName(), TagTechnology.MIFARE_CLASSIC);
    techStringToCodeMap.put(MifareUltralight.class.getName(), TagTechnology.MIFARE_ULTRALIGHT);
    techStringToCodeMap.put(Ndef.class.getName(), TagTechnology.NDEF);
    techStringToCodeMap.put(NdefFormatable.class.getName(), TagTechnology.NDEF_FORMATABLE);
    techStringToCodeMap.put(NfcA.class.getName(), TagTechnology.NFC_A);
    techStringToCodeMap.put(NfcB.class.getName(), TagTechnology.NFC_B);
    techStringToCodeMap.put(NfcF.class.getName(), TagTechnology.NFC_F);
    techStringToCodeMap.put(NfcV.class.getName(), TagTechnology.NFC_V);
    techStringToCodeMap.put(NfcBarcode.class.getName(), TagTechnology.NFC_BARCODE);

    return techStringToCodeMap;
}
 
Example #2
Source File: BlogViewer.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // Get the NFC Adapter.
  NfcManager nfcManager = (NfcManager)getSystemService(Context.NFC_SERVICE);
  mNFCAdapter = nfcManager.getDefaultAdapter();

  // Create the Pending Intent.
  int flags = 0;
  Intent nfcIntent = new Intent(this, getClass());
  nfcIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
  mNFCPendingIntent =
    PendingIntent.getActivity(this, NFC_REQUEST_CODE, nfcIntent, flags);

  // Create an Intent Filter limited to the URI or MIME type to
  // intercept TAG scans from.
  IntentFilter tagIntentFilter =
    new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
  tagIntentFilter.addDataScheme("http");
  tagIntentFilter.addDataAuthority("blog.radioactiveyak.com", null);
  mIntentFiltersArray = new IntentFilter[] { tagIntentFilter };

  // Create an array of technologies to handle.
  mTechListsArray = new String[][] {
    new String[] {
      NfcF.class.getName()
    }
  };

  // Process the Intent used to start the Activity/
  String action = getIntent().getAction();
  if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
    processIntent(getIntent());
}
 
Example #3
Source File: AppRunnerActivity.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
public void initializeNFC() {

        if (nfcInit == false) {
            PackageManager pm = getPackageManager();
            nfcSupported = pm.hasSystemFeature(PackageManager.FEATURE_NFC);

            if (nfcSupported == false) {
                return;
            }

            // when is in foreground
            MLog.d(TAG, "starting NFC");
            mAdapter = NfcAdapter.getDefaultAdapter(this);

            // PedingIntent will be delivered to this activity
            mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

            // Setup an intent filter for all MIME based dispatches
            IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
            try {
                ndef.addDataType("*/*");
            } catch (IntentFilter.MalformedMimeTypeException e) {
                throw new RuntimeException("fail", e);
            }
            mFilters = new IntentFilter[]{ndef,};

            // Setup a tech list for all NfcF tags
            mTechLists = new String[][]{new String[]{NfcF.class.getName()}};
            nfcInit = true;
        }
    }
 
Example #4
Source File: FelicaReader.java    From nfcard with GNU General Public License v3.0 5 votes vote down vote up
static void readCard(NfcF tech, Card card) throws IOException {

		final FeliCa.Tag tag = new FeliCa.Tag(tech);

		tag.connect();

		/*
		 * 
		FeliCa.SystemCode systems[] = tag.getSystemCodeList();
		if (systems.length == 0) {
			systems = new FeliCa.SystemCode[] { new FeliCa.SystemCode(
					tag.getSystemCodeByte()) };
		}

		for (final FeliCa.SystemCode sys : systems)
			card.addApplication(readApplication(tag, sys.toInt()));
		*/
		
		// better old card compatibility 
		card.addApplication(readApplication(tag, SYS_OCTOPUS));

		try {
			card.addApplication(readApplication(tag, SYS_SZT));
		} catch (IOException e) {
			// for early version of OCTOPUS which will throw shit
		}

		tag.close();
	}
 
Example #5
Source File: FelicaReader.java    From NFCard with GNU General Public License v3.0 5 votes vote down vote up
static void readCard(NfcF tech, Card card) throws IOException {

		final FeliCa.Tag tag = new FeliCa.Tag(tech);

		tag.connect();

		/*
		 * 
		FeliCa.SystemCode systems[] = tag.getSystemCodeList();
		if (systems.length == 0) {
			systems = new FeliCa.SystemCode[] { new FeliCa.SystemCode(
					tag.getSystemCodeByte()) };
		}

		for (final FeliCa.SystemCode sys : systems)
			card.addApplication(readApplication(tag, sys.toInt()));
		*/
		
		// better old card compatibility 
		card.addApplication(readApplication(tag, SYS_OCTOPUS));

		try {
			card.addApplication(readApplication(tag, SYS_SZT));
		} catch (IOException e) {
			// for early version of OCTOPUS which will throw shit
		}

		tag.close();
	}
 
Example #6
Source File: ForegroundDispatch.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    setContentView(R.layout.foreground_dispatch);
    mText = (TextView) findViewById(R.id.text);
    mText.setText("Scan a tag");

    mAdapter = NfcAdapter.getDefaultAdapter(this);

    // Create a generic PendingIntent that will be deliver to this activity. The NFC stack
    // will fill in the intent with the details of the discovered tag before delivering to
    // this activity.
    mPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    // Setup an intent filter for all MIME based dispatches
    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
        ndef.addDataType("*/*");
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("fail", e);
    }
    mFilters = new IntentFilter[] {
            ndef,
    };

    // Setup a tech list for all NfcF tags
    mTechLists = new String[][] { new String[] { NfcF.class.getName() } };
}
 
Example #7
Source File: Tag.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private String[] generateTechStringList(int[] techList) {
    final int size = techList.length;
    String[] strings = new String[size];
    for (int i = 0; i < size; i++) {
        switch (techList[i]) {
            case TagTechnology.ISO_DEP:
                strings[i] = IsoDep.class.getName();
                break;
            case TagTechnology.MIFARE_CLASSIC:
                strings[i] = MifareClassic.class.getName();
                break;
            case TagTechnology.MIFARE_ULTRALIGHT:
                strings[i] = MifareUltralight.class.getName();
                break;
            case TagTechnology.NDEF:
                strings[i] = Ndef.class.getName();
                break;
            case TagTechnology.NDEF_FORMATABLE:
                strings[i] = NdefFormatable.class.getName();
                break;
            case TagTechnology.NFC_A:
                strings[i] = NfcA.class.getName();
                break;
            case TagTechnology.NFC_B:
                strings[i] = NfcB.class.getName();
                break;
            case TagTechnology.NFC_F:
                strings[i] = NfcF.class.getName();
                break;
            case TagTechnology.NFC_V:
                strings[i] = NfcV.class.getName();
                break;
            case TagTechnology.NFC_BARCODE:
                strings[i] = NfcBarcode.class.getName();
                break;
            default:
                throw new IllegalArgumentException("Unknown tech type " + techList[i]);
        }
    }
    return strings;
}
 
Example #8
Source File: FeliCa.java    From nfcard with GNU General Public License v3.0 4 votes vote down vote up
public Tag(NfcF tag) {
	nfcTag = tag;
	sys = tag.getSystemCode();
	idm = new IDm(tag.getTag().getId());
	pmm = new PMm(tag.getManufacturer());
}
 
Example #9
Source File: FeliCa.java    From NFCard with GNU General Public License v3.0 4 votes vote down vote up
public Tag(NfcF tag) {
	nfcTag = tag;
	sys = tag.getSystemCode();
	idm = new IDm(tag.getTag().getId());
	pmm = new PMm(tag.getManufacturer());
}
 
Example #10
Source File: NFCHandler.java    From timelapse-sony with GNU General Public License v3.0 4 votes vote down vote up
public static String[][] getTechListArray() {
    return new String[][]{new String[]{NfcF.class.getName()}};
}
 
Example #11
Source File: ReaderManager.java    From nfcard with GNU General Public License v3.0 3 votes vote down vote up
private Card readCard(Tag tag) {

		final Card card = new Card();

		try {

			publishProgress(SPEC.EVENT.READING);

			card.setProperty(SPEC.PROP.ID, Util.toHexString(tag.getId()));

			final IsoDep isodep = IsoDep.get(tag);
			if (isodep != null)
				StandardPboc.readCard(isodep, card);

			final NfcF nfcf = NfcF.get(tag);
			if (nfcf != null)
				FelicaReader.readCard(nfcf, card);

			publishProgress(SPEC.EVENT.IDLE);

		} catch (Exception e) {
			card.setProperty(SPEC.PROP.EXCEPTION, e);
			publishProgress(SPEC.EVENT.ERROR);
		}

		return card;
	}
 
Example #12
Source File: ReaderManager.java    From NFCard with GNU General Public License v3.0 3 votes vote down vote up
private Card readCard(Tag tag) {

		final Card card = new Card();

		try {

			publishProgress(SPEC.EVENT.READING);

			card.setProperty(SPEC.PROP.ID, Util.toHexString(tag.getId()));

			final IsoDep isodep = IsoDep.get(tag);
			if (isodep != null)
				StandardPboc.readCard(isodep, card);

			final NfcF nfcf = NfcF.get(tag);
			if (nfcf != null)
				FelicaReader.readCard(nfcf, card);

			publishProgress(SPEC.EVENT.IDLE);

		} catch (Exception e) {
			card.setProperty(SPEC.PROP.EXCEPTION, e);
			publishProgress(SPEC.EVENT.ERROR);
		}

		return card;
	}