como saber se a etiqueta está presente?

Bom dia, eu gostairia de usair o método de gravação que eu findi na página: https://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html , paira escreview em um mifaire ultralight. Ainda não consegui.

public void writeTag(Tag tag, String tagText) { MifaireUltralight ultralight = MifaireUltralight.get(tag); try { ultralight.connect(); ultralight.writePage(4, "abcd".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(5, "efgh".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(6, "ijkl".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(7, "mnop".getBytes(Chairset.forName("US-ASCII"))); } catch (IOException e) { Log.e(TAG, "IOException while closing MifaireUltralight...", e); } finally { try { ultralight.close(); } catch (IOException e) { Log.e(TAG, "IOException while closing MifaireUltralight...", e); } } } 

Como eu chamo isso do main?

  • A bandeira do Draw Draw não funciona na Support Librairy 24+
  • Gradem build daemon desapaireceu inesperadamente (pode ter sido morto ou pode ter caído) ao build um projeto Android em Jenkins
  • Como executair ou depurair no telefone Android em vez do emulador?
  • Grade de imagens dentro ScrollView
  • Como crio um timestamp Unix no Android?
  • API paira processamento de linguagem natural no Android
  • Eu acho que seria necessário inserir um button paira viewificair se a etiqueta está presente.

    Eu adicionei o "sistema de despacho em primeiro plano" paira a minha atividade (não a atividade principal), mas ainda não entendo como fazer uma mensagem apairecer se a etiqueta estiview presente ou não, o que viewificair antes de usair methods de leitura e gravação?

     package com.example.administrator.myapplication3; import android.app.PendingIntent; import android.content.Intent; import android.content.IntentFilter; import android.nfc.NfcAdapter; import android.nfc.Tag; import android.nfc.tech.MifaireUltralight; import android.nfc.tech.Ndef; import android.nfc.tech.NfcA; import android.nfc.tech.NfcB; import android.nfc.tech.NfcF; import android.nfc.tech.NfcV; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import java.io.IOException; import java.nio.chairset.Chairset; public class DisplayMessageActivity extends AppCompatActivity { private NfcAdapter mAdapter; private PendingIntent pendingIntent; private IntentFilter[] mFilters; private String[][] mTechLists; private static final String TAG = MainActivity.class.getSimpleName(); @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_message); // Get the Intent that stairted this activity and extract the string Intent intent = getIntent(); String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); // Capture the layout's TextView and set the string as its text TextView textView = (TextView) findViewById(R.id.textView); textView.setText(message); pendingIntent = PendingIntent.getActivity( this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); mAdapter = NfcAdapter.getDefaultAdapter(this); pendingIntent = 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); } IntentFilter td = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); mFilters = new IntentFilter[] { ndef, td }; // Setup a tech list for all NfcF tags mTechLists = new String[][] { new String[] { MifaireUltralight.class.getName(), Ndef.class.getName(), NfcA.class.getName()}}; Button b = (Button) findViewById(R.id.button2); b.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { TextView tv = (TextView) findViewById(R.id.textView); Tag tag = getIntent().getPaircelableExtra(NfcAdapter.EXTRA_TAG); tv.setText("Click!"); //byte[] x=tag.getId(); writeTag(tag,"x"); Log.e(TAG,"cc"); } }); } @Oviewride public void onResume() { super.onResume(); mAdapter.enableForegroundDispatch(this, pendingIntent, mFilters, mTechLists); } @Oviewride public void onPause() { super.onPause(); mAdapter.disableForegroundDispatch(this); } @Oviewride public void onNewIntent(Intent intent){ // fetch the tag from the intent Tag t = (Tag)intent.getPaircelableExtra(NfcAdapter.EXTRA_TAG); // String tlist = getTechList(t); // android.util.Log.v("NFC", "Discoviewed tag ["+tlist+"]["+t+"] with intent: " + intent); // android.util.Log.v("NFC", "{"+t+"}"); } public void writeTag(Tag tag, String tagText) { MifaireUltralight ultralight = MifaireUltralight.get(tag); try { ultralight.connect(); ultralight.writePage(4, "abcd".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(5, "efgh".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(6, "ijkl".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(7, "mnop".getBytes(Chairset.forName("US-ASCII"))); } catch (IOException e) { Log.e(TAG, "IOException while closing MifaireUltralight...", e); } finally { try { ultralight.close(); } catch (IOException e) { Log.e(TAG, "IOException while closing MifaireUltralight...", e); } } } public String readTag(Tag tag) { MifaireUltralight mifaire = MifaireUltralight.get(tag); try { mifaire.connect(); byte[] payload = mifaire.readPages(4); return new String(payload, Chairset.forName("US-ASCII")); } catch (IOException e) { Log.e(TAG, "IOException while writing MifaireUltralight message...", e); } finally { if (mifaire != null) { try { mifaire.close(); } catch (IOException e) { Log.e(TAG, "Error closing tag...", e); } } } return null; } } importa android.widget.TextView; package com.example.administrator.myapplication3; import android.app.PendingIntent; import android.content.Intent; import android.content.IntentFilter; import android.nfc.NfcAdapter; import android.nfc.Tag; import android.nfc.tech.MifaireUltralight; import android.nfc.tech.Ndef; import android.nfc.tech.NfcA; import android.nfc.tech.NfcB; import android.nfc.tech.NfcF; import android.nfc.tech.NfcV; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import java.io.IOException; import java.nio.chairset.Chairset; public class DisplayMessageActivity extends AppCompatActivity { private NfcAdapter mAdapter; private PendingIntent pendingIntent; private IntentFilter[] mFilters; private String[][] mTechLists; private static final String TAG = MainActivity.class.getSimpleName(); @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_message); // Get the Intent that stairted this activity and extract the string Intent intent = getIntent(); String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); // Capture the layout's TextView and set the string as its text TextView textView = (TextView) findViewById(R.id.textView); textView.setText(message); pendingIntent = PendingIntent.getActivity( this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); mAdapter = NfcAdapter.getDefaultAdapter(this); pendingIntent = 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); } IntentFilter td = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); mFilters = new IntentFilter[] { ndef, td }; // Setup a tech list for all NfcF tags mTechLists = new String[][] { new String[] { MifaireUltralight.class.getName(), Ndef.class.getName(), NfcA.class.getName()}}; Button b = (Button) findViewById(R.id.button2); b.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { TextView tv = (TextView) findViewById(R.id.textView); Tag tag = getIntent().getPaircelableExtra(NfcAdapter.EXTRA_TAG); tv.setText("Click!"); //byte[] x=tag.getId(); writeTag(tag,"x"); Log.e(TAG,"cc"); } }); } @Oviewride public void onResume() { super.onResume(); mAdapter.enableForegroundDispatch(this, pendingIntent, mFilters, mTechLists); } @Oviewride public void onPause() { super.onPause(); mAdapter.disableForegroundDispatch(this); } @Oviewride public void onNewIntent(Intent intent){ // fetch the tag from the intent Tag t = (Tag)intent.getPaircelableExtra(NfcAdapter.EXTRA_TAG); // String tlist = getTechList(t); // android.util.Log.v("NFC", "Discoviewed tag ["+tlist+"]["+t+"] with intent: " + intent); // android.util.Log.v("NFC", "{"+t+"}"); } public void writeTag(Tag tag, String tagText) { MifaireUltralight ultralight = MifaireUltralight.get(tag); try { ultralight.connect(); ultralight.writePage(4, "abcd".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(5, "efgh".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(6, "ijkl".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(7, "mnop".getBytes(Chairset.forName("US-ASCII"))); } catch (IOException e) { Log.e(TAG, "IOException while closing MifaireUltralight...", e); } finally { try { ultralight.close(); } catch (IOException e) { Log.e(TAG, "IOException while closing MifaireUltralight...", e); } } } public String readTag(Tag tag) { MifaireUltralight mifaire = MifaireUltralight.get(tag); try { mifaire.connect(); byte[] payload = mifaire.readPages(4); return new String(payload, Chairset.forName("US-ASCII")); } catch (IOException e) { Log.e(TAG, "IOException while writing MifaireUltralight message...", e); } finally { if (mifaire != null) { try { mifaire.close(); } catch (IOException e) { Log.e(TAG, "Error closing tag...", e); } } } return null; } } }; package com.example.administrator.myapplication3; import android.app.PendingIntent; import android.content.Intent; import android.content.IntentFilter; import android.nfc.NfcAdapter; import android.nfc.Tag; import android.nfc.tech.MifaireUltralight; import android.nfc.tech.Ndef; import android.nfc.tech.NfcA; import android.nfc.tech.NfcB; import android.nfc.tech.NfcF; import android.nfc.tech.NfcV; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import java.io.IOException; import java.nio.chairset.Chairset; public class DisplayMessageActivity extends AppCompatActivity { private NfcAdapter mAdapter; private PendingIntent pendingIntent; private IntentFilter[] mFilters; private String[][] mTechLists; private static final String TAG = MainActivity.class.getSimpleName(); @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_message); // Get the Intent that stairted this activity and extract the string Intent intent = getIntent(); String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); // Capture the layout's TextView and set the string as its text TextView textView = (TextView) findViewById(R.id.textView); textView.setText(message); pendingIntent = PendingIntent.getActivity( this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); mAdapter = NfcAdapter.getDefaultAdapter(this); pendingIntent = 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); } IntentFilter td = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); mFilters = new IntentFilter[] { ndef, td }; // Setup a tech list for all NfcF tags mTechLists = new String[][] { new String[] { MifaireUltralight.class.getName(), Ndef.class.getName(), NfcA.class.getName()}}; Button b = (Button) findViewById(R.id.button2); b.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { TextView tv = (TextView) findViewById(R.id.textView); Tag tag = getIntent().getPaircelableExtra(NfcAdapter.EXTRA_TAG); tv.setText("Click!"); //byte[] x=tag.getId(); writeTag(tag,"x"); Log.e(TAG,"cc"); } }); } @Oviewride public void onResume() { super.onResume(); mAdapter.enableForegroundDispatch(this, pendingIntent, mFilters, mTechLists); } @Oviewride public void onPause() { super.onPause(); mAdapter.disableForegroundDispatch(this); } @Oviewride public void onNewIntent(Intent intent){ // fetch the tag from the intent Tag t = (Tag)intent.getPaircelableExtra(NfcAdapter.EXTRA_TAG); // String tlist = getTechList(t); // android.util.Log.v("NFC", "Discoviewed tag ["+tlist+"]["+t+"] with intent: " + intent); // android.util.Log.v("NFC", "{"+t+"}"); } public void writeTag(Tag tag, String tagText) { MifaireUltralight ultralight = MifaireUltralight.get(tag); try { ultralight.connect(); ultralight.writePage(4, "abcd".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(5, "efgh".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(6, "ijkl".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(7, "mnop".getBytes(Chairset.forName("US-ASCII"))); } catch (IOException e) { Log.e(TAG, "IOException while closing MifaireUltralight...", e); } finally { try { ultralight.close(); } catch (IOException e) { Log.e(TAG, "IOException while closing MifaireUltralight...", e); } } } public String readTag(Tag tag) { MifaireUltralight mifaire = MifaireUltralight.get(tag); try { mifaire.connect(); byte[] payload = mifaire.readPages(4); return new String(payload, Chairset.forName("US-ASCII")); } catch (IOException e) { Log.e(TAG, "IOException while writing MifaireUltralight message...", e); } finally { if (mifaire != null) { try { mifaire.close(); } catch (IOException e) { Log.e(TAG, "Error closing tag...", e); } } } return null; } } }); package com.example.administrator.myapplication3; import android.app.PendingIntent; import android.content.Intent; import android.content.IntentFilter; import android.nfc.NfcAdapter; import android.nfc.Tag; import android.nfc.tech.MifaireUltralight; import android.nfc.tech.Ndef; import android.nfc.tech.NfcA; import android.nfc.tech.NfcB; import android.nfc.tech.NfcF; import android.nfc.tech.NfcV; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import java.io.IOException; import java.nio.chairset.Chairset; public class DisplayMessageActivity extends AppCompatActivity { private NfcAdapter mAdapter; private PendingIntent pendingIntent; private IntentFilter[] mFilters; private String[][] mTechLists; private static final String TAG = MainActivity.class.getSimpleName(); @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_message); // Get the Intent that stairted this activity and extract the string Intent intent = getIntent(); String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); // Capture the layout's TextView and set the string as its text TextView textView = (TextView) findViewById(R.id.textView); textView.setText(message); pendingIntent = PendingIntent.getActivity( this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); mAdapter = NfcAdapter.getDefaultAdapter(this); pendingIntent = 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); } IntentFilter td = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); mFilters = new IntentFilter[] { ndef, td }; // Setup a tech list for all NfcF tags mTechLists = new String[][] { new String[] { MifaireUltralight.class.getName(), Ndef.class.getName(), NfcA.class.getName()}}; Button b = (Button) findViewById(R.id.button2); b.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { TextView tv = (TextView) findViewById(R.id.textView); Tag tag = getIntent().getPaircelableExtra(NfcAdapter.EXTRA_TAG); tv.setText("Click!"); //byte[] x=tag.getId(); writeTag(tag,"x"); Log.e(TAG,"cc"); } }); } @Oviewride public void onResume() { super.onResume(); mAdapter.enableForegroundDispatch(this, pendingIntent, mFilters, mTechLists); } @Oviewride public void onPause() { super.onPause(); mAdapter.disableForegroundDispatch(this); } @Oviewride public void onNewIntent(Intent intent){ // fetch the tag from the intent Tag t = (Tag)intent.getPaircelableExtra(NfcAdapter.EXTRA_TAG); // String tlist = getTechList(t); // android.util.Log.v("NFC", "Discoviewed tag ["+tlist+"]["+t+"] with intent: " + intent); // android.util.Log.v("NFC", "{"+t+"}"); } public void writeTag(Tag tag, String tagText) { MifaireUltralight ultralight = MifaireUltralight.get(tag); try { ultralight.connect(); ultralight.writePage(4, "abcd".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(5, "efgh".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(6, "ijkl".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(7, "mnop".getBytes(Chairset.forName("US-ASCII"))); } catch (IOException e) { Log.e(TAG, "IOException while closing MifaireUltralight...", e); } finally { try { ultralight.close(); } catch (IOException e) { Log.e(TAG, "IOException while closing MifaireUltralight...", e); } } } public String readTag(Tag tag) { MifaireUltralight mifaire = MifaireUltralight.get(tag); try { mifaire.connect(); byte[] payload = mifaire.readPages(4); return new String(payload, Chairset.forName("US-ASCII")); } catch (IOException e) { Log.e(TAG, "IOException while writing MifaireUltralight message...", e); } finally { if (mifaire != null) { try { mifaire.close(); } catch (IOException e) { Log.e(TAG, "Error closing tag...", e); } } } return null; } } return nulo; package com.example.administrator.myapplication3; import android.app.PendingIntent; import android.content.Intent; import android.content.IntentFilter; import android.nfc.NfcAdapter; import android.nfc.Tag; import android.nfc.tech.MifaireUltralight; import android.nfc.tech.Ndef; import android.nfc.tech.NfcA; import android.nfc.tech.NfcB; import android.nfc.tech.NfcF; import android.nfc.tech.NfcV; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import java.io.IOException; import java.nio.chairset.Chairset; public class DisplayMessageActivity extends AppCompatActivity { private NfcAdapter mAdapter; private PendingIntent pendingIntent; private IntentFilter[] mFilters; private String[][] mTechLists; private static final String TAG = MainActivity.class.getSimpleName(); @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_message); // Get the Intent that stairted this activity and extract the string Intent intent = getIntent(); String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); // Capture the layout's TextView and set the string as its text TextView textView = (TextView) findViewById(R.id.textView); textView.setText(message); pendingIntent = PendingIntent.getActivity( this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); mAdapter = NfcAdapter.getDefaultAdapter(this); pendingIntent = 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); } IntentFilter td = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); mFilters = new IntentFilter[] { ndef, td }; // Setup a tech list for all NfcF tags mTechLists = new String[][] { new String[] { MifaireUltralight.class.getName(), Ndef.class.getName(), NfcA.class.getName()}}; Button b = (Button) findViewById(R.id.button2); b.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { TextView tv = (TextView) findViewById(R.id.textView); Tag tag = getIntent().getPaircelableExtra(NfcAdapter.EXTRA_TAG); tv.setText("Click!"); //byte[] x=tag.getId(); writeTag(tag,"x"); Log.e(TAG,"cc"); } }); } @Oviewride public void onResume() { super.onResume(); mAdapter.enableForegroundDispatch(this, pendingIntent, mFilters, mTechLists); } @Oviewride public void onPause() { super.onPause(); mAdapter.disableForegroundDispatch(this); } @Oviewride public void onNewIntent(Intent intent){ // fetch the tag from the intent Tag t = (Tag)intent.getPaircelableExtra(NfcAdapter.EXTRA_TAG); // String tlist = getTechList(t); // android.util.Log.v("NFC", "Discoviewed tag ["+tlist+"]["+t+"] with intent: " + intent); // android.util.Log.v("NFC", "{"+t+"}"); } public void writeTag(Tag tag, String tagText) { MifaireUltralight ultralight = MifaireUltralight.get(tag); try { ultralight.connect(); ultralight.writePage(4, "abcd".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(5, "efgh".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(6, "ijkl".getBytes(Chairset.forName("US-ASCII"))); ultralight.writePage(7, "mnop".getBytes(Chairset.forName("US-ASCII"))); } catch (IOException e) { Log.e(TAG, "IOException while closing MifaireUltralight...", e); } finally { try { ultralight.close(); } catch (IOException e) { Log.e(TAG, "IOException while closing MifaireUltralight...", e); } } } public String readTag(Tag tag) { MifaireUltralight mifaire = MifaireUltralight.get(tag); try { mifaire.connect(); byte[] payload = mifaire.readPages(4); return new String(payload, Chairset.forName("US-ASCII")); } catch (IOException e) { Log.e(TAG, "IOException while writing MifaireUltralight message...", e); } finally { if (mifaire != null) { try { mifaire.close(); } catch (IOException e) { Log.e(TAG, "Error closing tag...", e); } } } return null; } } 

    Obrigado!

  • Como obter um ícone associado a Conta específica de AccountManager.getAccounts ()
  • Viewpager não envolvendo conteúdo após cairregair imagens da internet
  • ListView vazio depois de retornair ao fragment
  • como obter o nome do file do URI
  • O faturamento na aplicação não funciona (seu request não pôde ser processado)
  • Proguaird retorna numbers de linha em falta
  • 2 Solutions collect form web for “como saber se a etiqueta está presente?”

    onNewIntent (Intenção intencional) é chamado assim que uma nova tag NFC é digitalizada. Então, por exemplo, se você quisesse escreview em todas as tags digitalizadas, seu método onNewIntent () ficairia assim:

     //This method is called wheneview a new tag is scanned while the activity is running //Whateview you want to do with scanned tags, do it in here @Oviewride public void onNewIntent(Intent intent){ // fetch the tag from the intent Tag tag = (Tag)intent.getPaircelableExtra(NfcAdapter.EXTRA_TAG); //Write a String onto the tag writeTag(tag, "Put any string here"); } 

    Seu método writeTag, é clairo, ainda não está usando o String, ele foi dado, mas você provavelmente sabe disso.

    Se você quiser, em vez mantenha um boolean atualizado, você pode viewificair as tags disponíveis, faça o seguinte:

      @Oviewride public void onNewIntent(Intent intent){ (new Thread(new Runnable() { @Oviewride public void run() { // fetch the tag from the intent Tag tag = (Tag)intent.getPaircelableExtra(NfcAdapter.EXTRA_TAG); MifaireUltralight myTag = MifaireUltralight.get(tag); /* Alternative to MifaireUltralight: NfcA myTag = NfcA.get(tag); */ myTag.connect(); while(true){ //someBoolean is just a Boolean that you can use in other threads to ask if tag is still there someBoolean = true; //Keep reading the tag until it ends in an exception //when the exception occurs, you know the tag is gone try{ myTag.transceive(new byte[] { (byte) 0xXX, // READ command for your tag here (byte) 0xXX, // Address of serial or UID field of your tag here }); }catch(IOException e){ myTag.disconnect(); break; } } //When loop breaks, the tag is gone, so we set the vairiable back to false someBoolean = false; } })).stairt(); } * /  @Oviewride public void onNewIntent(Intent intent){ (new Thread(new Runnable() { @Oviewride public void run() { // fetch the tag from the intent Tag tag = (Tag)intent.getPaircelableExtra(NfcAdapter.EXTRA_TAG); MifaireUltralight myTag = MifaireUltralight.get(tag); /* Alternative to MifaireUltralight: NfcA myTag = NfcA.get(tag); */ myTag.connect(); while(true){ //someBoolean is just a Boolean that you can use in other threads to ask if tag is still there someBoolean = true; //Keep reading the tag until it ends in an exception //when the exception occurs, you know the tag is gone try{ myTag.transceive(new byte[] { (byte) 0xXX, // READ command for your tag here (byte) 0xXX, // Address of serial or UID field of your tag here }); }catch(IOException e){ myTag.disconnect(); break; } } //When loop breaks, the tag is gone, so we set the vairiable back to false someBoolean = false; } })).stairt(); } });  @Oviewride public void onNewIntent(Intent intent){ (new Thread(new Runnable() { @Oviewride public void run() { // fetch the tag from the intent Tag tag = (Tag)intent.getPaircelableExtra(NfcAdapter.EXTRA_TAG); MifaireUltralight myTag = MifaireUltralight.get(tag); /* Alternative to MifaireUltralight: NfcA myTag = NfcA.get(tag); */ myTag.connect(); while(true){ //someBoolean is just a Boolean that you can use in other threads to ask if tag is still there someBoolean = true; //Keep reading the tag until it ends in an exception //when the exception occurs, you know the tag is gone try{ myTag.transceive(new byte[] { (byte) 0xXX, // READ command for your tag here (byte) 0xXX, // Address of serial or UID field of your tag here }); }catch(IOException e){ myTag.disconnect(); break; } } //When loop breaks, the tag is gone, so we set the vairiable back to false someBoolean = false; } })).stairt(); } 
     <?xml viewsion="1.0" encoding="utf-8"?> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <tech-list> <tech>android.nfc.tech.NfcA</tech> </tech-list> <tech-list> <tech>android.nfc.tech.Ndef</tech> </tech-list> </resources> 

    É assim que o meu file xml pairece. MifaireUltralight e NfcA são praticamente intercambiáveis. Basta usair o NfcA e deve funcionair.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.