According documentation, connect and format of NdefFormatable may cause RF 
activity and may block.

They recommend call close from another thread. This not worked for me, 
because when i call close, the thread is blocked too.


This is my code:


    private void formatTag(Tag tag, NdefMessage ndefMessage) throws 
IOException, FormatException {

    final NdefFormatable ndefFormatable = NdefFormatable.get(tag);

    if (ndefFormatable == null) {
        return;
    }

    Thread thread = new Thread() {
        @Override
        public void run() {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            try {
                ndefFormatable.close();
                Log.v("MyApp", "Forced close NFC");
            } catch (IOException e) {
                Log.v("MyApp", "Disconnect failed: " + e.getMessage());
            }
        }
    };
    thread.start();
    ndefFormatable.connect();
    ndefFormatable.format(ndefMessage);
    ndefFormatable.close();}


Note 1: the formatTag is called from a AsyncTask
Note 2: This problem occurs on LG L90 device. I have tested on Moto X (1st 
generation) and the problem not happens.

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/2b7b0c22-6c9d-4fdb-a6b1-ab042661d889%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to