List of usage examples for android.nfc NfcAdapter ACTION_TECH_DISCOVERED
String ACTION_TECH_DISCOVERED
To view the source code for android.nfc NfcAdapter ACTION_TECH_DISCOVERED.
Click Source Link
From source file:org.irmacard.androidmanagement.CredentialListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Pass the list of CredentialPackages on to the ListFragement Intent intent = getIntent();/*from w ww . jav a2s . c om*/ @SuppressWarnings("unchecked") ArrayList<CredentialPackage> credentials = (ArrayList<CredentialPackage>) intent .getSerializableExtra(WaitingForCardActivity.EXTRA_CREDENTIAL_PACKAGES); setCredentials(credentials); @SuppressWarnings("unchecked") ArrayList<LogEntry> logs = (ArrayList<LogEntry>) intent .getSerializableExtra(WaitingForCardActivity.EXTRA_LOG_ENTRIES); setLogs(logs); Tag tag = (Tag) intent.getParcelableExtra(WaitingForCardActivity.EXTRA_TAG); setTag(tag); cardPin = (String) intent.getSerializableExtra(WaitingForCardActivity.EXTRA_CARD_PIN); cardVersion = (CardVersion) intent.getSerializableExtra(WaitingForCardActivity.EXTRA_CARD_VERSION); setContentView(R.layout.activity_credential_list); if (findViewById(R.id.credential_detail_container) != null) { // The detail container view will be present only in the // large-screen layouts (res/values-large and // res/values-sw600dp). If this view is present, then the // activity should be in two-pane mode. mTwoPane = true; // In two-pane mode, list items should be given the // 'activated' state when touched. ((MenuFragment) getSupportFragmentManager().findFragmentById(R.id.credential_menu_fragment)) .setTwoPaneMode(true); InitFragment initFragment = new InitFragment(); getSupportFragmentManager().beginTransaction().replace(R.id.credential_detail_container, initFragment) .commit(); Log.i("blaat", "Simulating initial click!!"); ((MenuFragment) getSupportFragmentManager().findFragmentById(R.id.credential_menu_fragment)) .simulateListClick(0); // Do not show action bar in two-pane mode getActionBar().hide(); } // NFC stuff nfcA = NfcAdapter.getDefaultAdapter(getApplicationContext()); mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); // Setup an intent filter for all TECH based dispatches IntentFilter tech = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED); mFilters = new IntentFilter[] { tech }; // Setup a tech list for all IsoDep cards mTechLists = new String[][] { new String[] { IsoDep.class.getName() } }; }
From source file:org.irmacard.androidmanagement.CredentialListActivity.java
@Override public void onResume() { super.onResume(); if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(getIntent().getAction())) { processIntent(getIntent());//w ww . j av a 2 s. c o m } if (nfcA != null) { nfcA.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists); } }
From source file:com.tananaev.passportreader.MainActivity.java
@Override public void onNewIntent(Intent intent) { if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())) { Tag tag = intent.getExtras().getParcelable(NfcAdapter.EXTRA_TAG); if (Arrays.asList(tag.getTechList()).contains("android.nfc.tech.IsoDep")) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); String passportNumber = preferences.getString(KEY_PASSPORT_NUMBER, null); String expirationDate = convertDate(preferences.getString(KEY_EXPIRATION_DATE, null)); String birthDate = convertDate(preferences.getString(KEY_BIRTH_DATE, null)); if (passportNumber != null && !passportNumber.isEmpty() && expirationDate != null && !expirationDate.isEmpty() && birthDate != null && !birthDate.isEmpty()) { BACKeySpec bacKey = new BACKey(passportNumber, birthDate, expirationDate); new ReadTask(IsoDep.get(tag), bacKey).execute(); mainLayout.setVisibility(View.GONE); loadingLayout.setVisibility(View.VISIBLE); } else { Snackbar.make(passportNumberView, R.string.error_input, Snackbar.LENGTH_SHORT).show(); }/*from w w w .j a va2s . c o m*/ } } }
From source file:foundme.uniroma2.it.professore.HomeActivity.java
private void handleIntent(Intent intent) { String action = intent.getAction(); if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) { String type = intent.getType(); if (Variables_it.MIME_TEXT_PLAIN.equals(type)) { Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); new NdefReaderTask().execute(tag); }/* w ww. j a v a2 s . c om*/ } else if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) { // In questo caso usermo la Tech Discovered Intent Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); String[] techList = tag.getTechList(); String searchedTech = Ndef.class.getName(); for (String tech : techList) { if (searchedTech.equals(tech)) { new NdefReaderTask().execute(tag); break; } } } }
From source file:org.ounl.lifelonglearninghub.mediaplayer.cast.refplayer.NFCVideoBrowserActivity.java
/** * On create, process NDEF message with its intent action * /*from ww w. j a v a2s . c o m*/ * @param intent */ private String resolveIntent(Intent intent) { Log.d(CLASSNAME, "resolveIntent is called intent:" + intent.toString()); String action = intent.getAction(); if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) || NfcAdapter.ACTION_TECH_DISCOVERED.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage[] msgs; if (rawMsgs != null) { msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i]; } } else { // Unknown tag type byte[] empty = new byte[0]; byte[] id = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID); Parcelable tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); byte[] payload = dumpTagData(tag).getBytes(); NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, id, payload); NdefMessage msg = new NdefMessage(new NdefRecord[] { record }); msgs = new NdefMessage[] { msg }; } return processNdefMessageArray(msgs); } return IParsedNdefCommand.COMMAND_UNKNOWN; }
From source file:be.brunoparmentier.wifikeyshare.ui.activities.WifiNetworkActivity.java
private void setupForegroundDispatch() { /* initialize the PendingIntent to start for the dispatch */ nfcPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); /* initialize the IntentFilters to override dispatching for */ nfcIntentFilters = new IntentFilter[3]; nfcIntentFilters[0] = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); nfcIntentFilters[0].addCategory(Intent.CATEGORY_DEFAULT); nfcIntentFilters[1] = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED); nfcIntentFilters[1].addCategory(Intent.CATEGORY_DEFAULT); nfcIntentFilters[2] = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); nfcIntentFilters[2].addCategory(Intent.CATEGORY_DEFAULT); try {//w w w. jav a 2 s .c om nfcIntentFilters[0].addDataType("*/*"); // Handle all MIME based dispatches. } catch (IntentFilter.MalformedMimeTypeException e) { Log.e(TAG, "setupForegroundDispatch: " + e.getMessage()); } /* Initialize the tech lists used to perform matching for dispatching of the * ACTION_TECH_DISCOVERED intent */ nfcTechLists = new String[][] {}; }
From source file:de.syss.MifareClassicTool.Common.java
/** * For Activities which want to treat new Intents as Intents with a new * Tag attached. If the given Intent has a Tag extra, it will be patched * by {@link MCReader#patchTag(Tag)} and {@link #mTag} as well as * {@link #mUID} will be updated. A Toast message will be shown in the * Context of the calling Activity. This method will also check if the * device/tag supports Mifare Classic (see return values and * {@link #checkMifareClassicSupport(Tag, Context)}). * @param intent The Intent which should be checked for a new Tag. * @param context The Context in which the Toast will be shown. * @return/*from ww w .j ava2s.c o m*/ * <ul> * <li>0 - The device/tag supports Mifare Classic</li> * <li>-1 - Device does not support Mifare Classic.</li> * <li>-2 - Tag does not support Mifare Classic.</li> * <li>-3 - Error (tag or context is null).</li> * <li>-4 - Wrong Intent (action is not "ACTION_TECH_DISCOVERED").</li> * </ul> * @see #mTag * @see #mUID * @see #checkMifareClassicSupport(Tag, Context) */ public static int treatAsNewTag(Intent intent, Context context) { // Check if Intent has a NFC Tag. if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())) { Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); tag = MCReader.patchTag(tag); setTag(tag); // Show Toast message with UID. String id = context.getResources().getString(R.string.info_new_tag_found) + " (UID: "; id += byte2HexString(tag.getId()); id += ")"; Toast.makeText(context, id, Toast.LENGTH_LONG).show(); return checkMifareClassicSupport(tag, context); } return -4; }
From source file:com.moonpi.tapunlock.MainActivity.java
@Override public void onClick(View v) { // If OK(setPin) clicked, ask user if sure; if yes, store PIN; else, go back if (v.getId() == R.id.setPin) { // If PIN length between 4 and 6, store PIN and toast successful if (pinEdit.length() >= 4 && pinEdit.length() <= 6) { new AlertDialog.Builder(this).setMessage(R.string.set_pin_confirmation) .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { settings.put("pin", String.valueOf(pinEdit.getText())); } catch (JSONException e) { e.printStackTrace(); }/*from w w w.ja va 2 s. co m*/ writeToJSON(); Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_pin_set, Toast.LENGTH_SHORT); toast.show(); imm.hideSoftInputFromWindow(pinEdit.getWindowToken(), 0); } }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { imm.hideSoftInputFromWindow(pinEdit.getWindowToken(), 0); // Do nothing, close dialog } }).show(); } // Toast user that PIN needs to be at least 4 digits long else { Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_pin_needs4digits, Toast.LENGTH_LONG); toast.show(); } } // If 'Refresh wallpaper' pressed, check if Android 4.2 or above, if yes // Store new blur var, if blur bigger than 0 re-blur wallpaper else if (v.getId() == R.id.refreshWallpaper) { if (Build.VERSION.SDK_INT > 16) { try { settings.put("blur", blur); } catch (JSONException e) { e.printStackTrace(); } writeToJSON(); // If blur is 0, don't change anything, just toast if (blur == 0) { Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_wallpaper_refreshed, Toast.LENGTH_SHORT); toast.show(); } // If blur is bigger than 0, get default wallpaper - to bitmap - fastblur bitmap - store else { // Check if TapUnlock folder exists, if not, create directory File folder = new File(Environment.getExternalStorageDirectory() + "/TapUnlock"); boolean folderSuccess = true; if (!folder.exists()) { folderSuccess = folder.mkdir(); } if (folderSuccess) { WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); final Drawable wallpaperDrawable = wallpaperManager.peekFastDrawable(); if (wallpaperDrawable != null) { // Display indeterminate progress bar while blurring progressBar.setVisibility(View.VISIBLE); new Thread(new Runnable() { @Override public void run() { Bitmap bitmapToBlur = ImageUtils.drawableToBitmap(wallpaperDrawable); Bitmap blurredWallpaper = null; if (bitmapToBlur != null) blurredWallpaper = ImageUtils.fastBlur(MainActivity.this, bitmapToBlur, blur); boolean stored = false; if (blurredWallpaper != null) { stored = ImageUtils.storeImage(blurredWallpaper); final boolean finalStored = stored; runOnUiThread(new Runnable() { @Override public void run() { progressBar.setVisibility(View.INVISIBLE); if (finalStored) { Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_wallpaper_refreshed, Toast.LENGTH_SHORT); toast.show(); } } }); } if (bitmapToBlur == null || blurredWallpaper == null || !stored) { runOnUiThread(new Runnable() { @Override public void run() { progressBar.setVisibility(View.INVISIBLE); Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_wallpaper_not_refreshed, Toast.LENGTH_SHORT); toast.show(); } }); } } }).start(); } else { Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_wallpaper_not_refreshed, Toast.LENGTH_SHORT); toast.show(); } } } } // If Android version less than 4.2, display toast cannot blur else { Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_cannot_blur, Toast.LENGTH_SHORT); toast.show(); } } // If '+' pressed else if (v.getId() == R.id.newTag) { if (nfcAdapter != null) { // If NFC is on, show scan dialog and enableForegroundDispatch if (nfcAdapter.isEnabled()) { nfcAdapter.enableForegroundDispatch(this, pIntent, new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED) }, new String[][] { new String[] { "android.nfc.tech.MifareClassic" }, new String[] { "android.nfc.tech.MifareUltralight" }, new String[] { "android.nfc.tech.NfcA" }, new String[] { "android.nfc.tech.NfcB" }, new String[] { "android.nfc.tech.NfcF" }, new String[] { "android.nfc.tech.NfcV" }, new String[] { "android.nfc.tech.Ndef" }, new String[] { "android.nfc.tech.IsoDep" }, new String[] { "android.nfc.tech.NdefFormatable" } }); MainActivity.this.showDialog(DIALOG_READ); } // NFC is off, prompt user to enable it and send him to NFC settings else { new AlertDialog.Builder(this).setTitle(R.string.nfc_off_dialog_title) .setMessage(R.string.nfc_off_dialog_message) .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Settings.ACTION_NFC_SETTINGS); startActivity(intent); } }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing, close dialog } }).show(); } } // NFC adapter is null else { new AlertDialog.Builder(this).setTitle(R.string.nfc_off_dialog_title) .setMessage(R.string.nfc_off_dialog_message) .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Settings.ACTION_NFC_SETTINGS); startActivity(intent); } }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing, close dialog } }).show(); } } }
From source file:com.moonpi.tapunlock.MainActivity.java
@Override protected void onNewIntent(Intent intent) { String action = intent.getAction(); if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) { Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); // Get tag ID and turn into String byte[] tagIDbytes = tag.getId(); tagID = bytesToHex(tagIDbytes);// ww w . java 2 s .c om if (!tagID.equals("")) { // Dismiss the 'Scan NFC Tag' dialog and show the 'Set tag name' dialog dismissDialog(DIALOG_READ); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); MainActivity.this.showDialog(DIALOG_SET_TAGNAME); } } }