@Override public void onClick(View v) { Log.d(TAG, "onClick"); if (v != null) { switch (v.getId()) { case R.id.btn_write: { Log.d(TAG, "case btn_write"); if (mEdTxt.getText() != null && !TextUtils.isEmpty(mEdTxt.getText().toString())) { String textToWrite = mEdTxt.getText().toString(); try { boolean writeSuccessful = writeTxtToTag(textToWrite, mTag); if (writeSuccessful) { Toast.makeText(this, "write successful!!", Toast.LENGTH_SHORT).show(); } } catch (IOException e) { e.printStackTrace(); Toast.makeText(this, "write failed! (IOException)", Toast.LENGTH_SHORT).show(); } catch (FormatException e) { e.printStackTrace(); Toast.makeText(this, "write failed! (FormatException)", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(this, "Empty!", Toast.LENGTH_SHORT).show(); } break; } case R.id.btn_clear_read: { Log.d(TAG, "case btn_clear_read"); mReadTxt.setText(EMPTY_MSG); mReadTxt.requestLayout(); Toast.makeText(this, "read string cleared!", Toast.LENGTH_SHORT).show(); break; } case R.id.btn_clear_write: { Log.d(TAG, "case btn_clear_write"); mEdTxt.setText(EMPTY_MSG); mReadTxt.requestLayout(); Toast.makeText(this, "write string cleared!", Toast.LENGTH_SHORT).show(); break; } default: break; } } }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public void onNewIntent(Intent intent) { // if(NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) { Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); // IsoDep isodep = IsoDep.get(tagFromIntent); // showMessage("isodep "+ isodep.toString(),'n'); // try { // libInstance.filterIntent(intent, mCallback); // } catch (CloneDetectedException e) { // e.printStackTrace(); // } // showDialog("NFC TAG", "writting in progress", DIALOG_TYPE_PROGRESS, ALERT_TYPE_FAILURE); try { NFCOps.write(tagData.toString(), tagFromIntent, intent.getAction()); stopProgress(); showDialog( "OPERATION SUCCESSFULL", "Tag written successfully" + "\nYou can now move the card away from the device", DIALOG_TYPE_ALERT, ALERT_TYPE_FAILURE); } catch (IOException e) { e.printStackTrace(); showDialog( "OPERATION FAILED", "Connection failed! " + "\nplease do not move the card away from the device while writting is in progress", DIALOG_TYPE_ALERT, ALERT_TYPE_FAILURE); } catch (FormatException e) { e.printStackTrace(); } finally { } // stopProgress(); // // showDialog("NFC TAG", "writting in progress", DIALOG_TYPE_PROGRESS, // ALERT_TYPE_FAILURE); // try { // libInstance.filterIntent(intent, mCallback); // } catch (CloneDetectedException e) { // e.printStackTrace(); // } // try { // NFCOps.write("abcd".toString(),tagFromIntent); // } catch (IOException e) { // e.printStackTrace(); // stopProgress(); // showDialog("OPERATION FAILED","Connection failed! \nplease do not move the // card away from the device while writting is in // progress",DIALOG_TYPE_ALERT,ALERT_TYPE_FAILURE); // } catch (FormatException e) { // stopProgress(); // e.printStackTrace(); // } }