當前位置: 首頁>>代碼示例>>Java>>正文


Java Ndef.get方法代碼示例

本文整理匯總了Java中android.nfc.tech.Ndef.get方法的典型用法代碼示例。如果您正苦於以下問題:Java Ndef.get方法的具體用法?Java Ndef.get怎麽用?Java Ndef.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.nfc.tech.Ndef的用法示例。


在下文中一共展示了Ndef.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeTag

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
/**
 * 寫入標簽
 *
 * @param message
 * @param tag
 * @return
 */
public static boolean writeTag(NdefMessage message, Tag tag) {
    int size = message.toByteArray().length;
    try {
        Ndef ndef = Ndef.get(tag);
        if (ndef != null) {
            ndef.connect();
            if (!ndef.isWritable()) {
                return false;
            }
            if (ndef.getMaxSize() < size) {
                return false;
            }
            ndef.writeNdefMessage(message);
            return true;
        }
    } catch (Exception e) {
    }
    return false;
}
 
開發者ID:jopenbox,項目名稱:android-nfc,代碼行數:27,代碼來源:WriteUriActivity.java

示例2: getNdefUsedSize

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
private DataReply getNdefUsedSize() {
    DataReply dataReply = new DataReply();
    int size = 0;
    if (currentTag != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
            Ndef ndef = Ndef.get(currentTag);
            if (ndef != null && ndef.getCachedNdefMessage() != null)
                size = ndef.getCachedNdefMessage().toByteArray().length;
            else {
                dataReply.setError(TAG_READING_ERROR);
                return dataReply;
            }
            try {
                if (ndef != null) ndef.close();
            } catch (IOException e) {
            }
        }
    }
    dataReply.setIntegerData(size);
    return dataReply;
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:22,代碼來源:NfcShield.java

示例3: getNdefMaxSize

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
private DataReply getNdefMaxSize() {
    DataReply dataReply = new DataReply();
    int maxSize = 0;
    if (currentTag != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
            Ndef ndef = Ndef.get(currentTag);
            if (ndef != null) {
                maxSize = ndef.getMaxSize();
                if (maxSize <= 0){
                    dataReply.setError(TAG_READING_ERROR);
                    return dataReply;
                }
            }else {
                dataReply.setError(TAG_READING_ERROR);
                return dataReply;
            }
            try {
                if (ndef != null) ndef.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    dataReply.setIntegerData(maxSize);
    return dataReply;
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:27,代碼來源:NfcShield.java

示例4: writeTAG

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
protected void writeTAG(Tag tag) throws IOException, FormatException {
    Ndef ndefTag = Ndef.get(tag);
    byte[] stringBytes = passphrase.getBytes();

    NdefRecord data = NdefRecord.createMime(CONST.NFC_MIME_LOGIN, stringBytes);
    NdefMessage message = new NdefMessage(data);

    if (ndefTag != null) { //write to formatted tag
        ndefTag.connect();
        ndefTag.writeNdefMessage(message);
    } else { //format the tag
        NdefFormatable format = NdefFormatable.get(tag);
        if(format != null) {
            format.connect();
            format.format(message);
        }
    }
}
 
開發者ID:gtom1984,項目名稱:Eulen,代碼行數:19,代碼來源:nfctagbase.java

示例5: nfcRead

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
public String nfcRead(Tag t)
{
    Tag tag = t;
    Ndef ndef = Ndef.get(tag);
    if (ndef == null) {
        return null;
    }
    NdefMessage ndefMessage = ndef.getCachedNdefMessage();
    NdefRecord[] records = ndefMessage.getRecords();
    for (NdefRecord ndefRecord : records)
    {
        if (ndefRecord.getTnf() == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT))
        {
            try {return readText(ndefRecord);} catch (UnsupportedEncodingException e) {}
        }
    }

    return null;

}
 
開發者ID:tawaasalage,項目名稱:RxBluetoothAuto,代碼行數:21,代碼來源:Home.java

示例6: doInBackground

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
@Override
protected NFCTag doInBackground(Intent... params) {
    Intent intent = params[0];

    Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    Ndef ndef = Ndef.get(tag);

    if (ndef == null) {
        return null;
    }

    NdefMessage ndefMessage = ndef.getCachedNdefMessage();

    if(ndefMessage != null) {
        NdefRecord[] records = ndefMessage.getRecords();
        for (NdefRecord ndefRecord : records) {
            try {
                return new NFCTag(ndefRecord).decode();
            } catch (UnsupportedEncodingException e) {
                Log.e("NFC", "Unsupported Encoding", e);
            }
        }
    }

    return null;
}
 
開發者ID:wesleydebruijn,項目名稱:android-nfc-wrapper,代碼行數:27,代碼來源:NFCReadTask.java

示例7: onNewIntent

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
@Override
protected void onNewIntent(Intent intent) {
    Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

    Log.d(TAG, "onNewIntent: "+intent.getAction());

    if(tag != null) {
        Toast.makeText(this, getString(R.string.message_tag_detected), Toast.LENGTH_SHORT).show();
        Ndef ndef = Ndef.get(tag);

        if (isDialogDisplayed) {

            if (isWrite) {

                String messageToWrite = mEtMessage.getText().toString();
                mNfcWriteFragment = (NFCWriteFragment) getFragmentManager().findFragmentByTag(NFCWriteFragment.TAG);
                mNfcWriteFragment.onNfcDetected(ndef,messageToWrite);

            } else {

                mNfcReadFragment = (NFCReadFragment)getFragmentManager().findFragmentByTag(NFCReadFragment.TAG);
                mNfcReadFragment.onNfcDetected(ndef);
            }
        }
    }
}
 
開發者ID:Learn2Crack,項目名稱:android-nfc-tag-read-write,代碼行數:27,代碼來源:MainActivity.java

示例8: writeTag

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
public void writeTag(Tag tag, NdefMessage message)
{
    if (tag != null) {
        try {
            Ndef ndefTag = Ndef.get(tag);

            if (ndefTag == null) {
                // Let's try to format the Tag in NDEF
                NdefFormatable nForm = NdefFormatable.get(tag);
                if (nForm != null) {
                    nForm.connect();
                    nForm.format(message);
                    nForm.close();
                }
            }
            else {
                ndefTag.connect();
                ndefTag.writeNdefMessage(message);
                ndefTag.close();
            }
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
}
 
開發者ID:The-Scrum-Masters,項目名稱:archive-carro-inteligente,代碼行數:27,代碼來源:NFCHandler.java

示例9: getTagText

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
public String getTagText() throws Exception
{
    if (tag == null)
    {
        throw new Exception("Please call handle new read as tag is null");
    }
    Ndef ndef = Ndef.get(tag);
    NdefMessage ndefMessage = ndef.getCachedNdefMessage();

    NdefRecord[] records = ndefMessage.getRecords();
    for (NdefRecord ndefRecord : records)
    {
        if (ndefRecord.getTnf() == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT))
        {
            try
            {
                return readText(ndefRecord);
            }
            catch (UnsupportedEncodingException e)
            {
                Toast.makeText(activity, "Unsupported encoding", Toast.LENGTH_SHORT).show();
            }
        }
    }
    return null;
}
 
開發者ID:The-Scrum-Masters,項目名稱:archive-carro-inteligente,代碼行數:27,代碼來源:NFCHandler.java

示例10: writeTag

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
/**
 * Writes an NdefMessage to a NFC tag
 */
public static void writeTag(NdefMessage message, Tag tag) throws Exception {
    int size = message.toByteArray().length;
    Ndef ndef = Ndef.get(tag);
    if (ndef != null) {
        ndef.connect();
        if (!ndef.isWritable()) {
            throw new NfcTagNotWritableException();
        }
        if (ndef.getMaxSize() < size) {
            throw new NfcTagInsufficientMemoryException(ndef.getMaxSize(), size);
        }
        ndef.writeNdefMessage(message);
    } else {
        NdefFormatable format = NdefFormatable.get(tag);
        if (format != null) {
            format.connect();
            format.format(message);
        } else {
            throw new IllegalArgumentException("Ndef format is NULL");
        }
    }
}
 
開發者ID:Power-Switch,項目名稱:PowerSwitch_Android,代碼行數:26,代碼來源:NfcHandler.java

示例11: doInBackground

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
@Override
protected String doInBackground(Tag... params) {
    Tag tag = params[0];

    Ndef ndef = Ndef.get(tag);
    if (ndef == null) {
        // NDEF is not supported by this Tag.
        return null;
    }

    NdefMessage ndefMessage = ndef.getCachedNdefMessage();

    NdefRecord[] records = ndefMessage.getRecords();
    for (NdefRecord ndefRecord : records) {
        if (ndefRecord.getTnf() == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT)) {
            try {
                return readText(ndefRecord);
            } catch (UnsupportedEncodingException e) {
                Log.e(TAG, "Unsupported Encoding", e);
            }
        }
    }

    return null;
}
 
開發者ID:hkboy,項目名稱:NFCPoC,代碼行數:26,代碼來源:MainActivity.java

示例12: doInBackground

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
@Override
protected ArrayList<String> doInBackground(Tag... params) {
    Tag tag = params[0];

    Ndef ndef = Ndef.get(tag);
    if (ndef == null) {
        // NDEF is not supported by this Tag.
        return null;
    }

    ArrayList<String> results = new ArrayList<>();
    NdefMessage ndefMessage = ndef.getCachedNdefMessage();
    NdefRecord[] records = ndefMessage.getRecords();
    for (NdefRecord ndefRecord : records) {
        if (ndefRecord.getTnf() == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT)) {
            try {
                results.add(readText(ndefRecord));
            } catch (UnsupportedEncodingException e) {
                Log.e(TAG, "Unsupported Encoding", e);
            }
        }
    }

    return results;
}
 
開發者ID:legendmohe,項目名稱:LEHomeMobile_android,代碼行數:26,代碼來源:NfcReadNdefAsyncTask.java

示例13: writableTag

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
public static boolean writableTag(Tag tag) {
    try {
        Ndef ndef = Ndef.get(tag);
        if (ndef != null) {
            ndef.connect();
            if (!ndef.isWritable()) {
                ndef.close();
                return false;
            }
            ndef.close();
            return true;
        }
    } catch (Exception e) {
    }
    return false;
}
 
開發者ID:legendmohe,項目名稱:LEHomeMobile_android,代碼行數:17,代碼來源:NFCHelper.java

示例14: readTag

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
private void readTag(Tag t) {
    byte[] id = t.getId();

    // get NDEF tag details
    Ndef ndefTag = Ndef.get(t);

    // get NDEF message details
    NdefMessage ndefMesg = ndefTag.getCachedNdefMessage();
    if (ndefMesg == null) {
        return;
    }
    NdefRecord[] ndefRecords = ndefMesg.getRecords();
    if (ndefRecords == null) {
        return;
    }
    for (NdefRecord record : ndefRecords) {
        short tnf = record.getTnf();
        String type = new String(record.getType());
        if (tnf == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(type.getBytes(), NdefRecord.RTD_URI)) {
            String url = new String(record.getPayload());
            recordBadge(url);
        }
    }
}
 
開發者ID:The-WebOps-Club,項目名稱:saarang-iosched,代碼行數:25,代碼來源:NfcBadgeActivity.java

示例15: readTagFromIntent

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
private void readTagFromIntent(Intent intent) {
    if (intent != null){
        String action = intent.getAction();
        if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
            tagReaded = true;

            // get NDEF tag details
            Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
            if (tag != null) {
                Ndef ndefTag = Ndef.get(tag);
                //int tagSize = ndefTag.getMaxSize();         // tag size
                tagIsWritable = ndefTag.isWritable();   // is tag writable?
                //String tagType = ndefTag.getType();            // tag type

                Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
                if (rawMsgs != null) {
                    NdefRecord[] records = ((NdefMessage) rawMsgs[0]).getRecords();
                    String text = ndefRecordToString(records[0]);
                    onTagReadListener.onTagRead(text);
                }
            }
        }
    }
}
 
開發者ID:henrichg,項目名稱:PhoneProfilesPlus,代碼行數:25,代碼來源:NFCTagReadWriteManager.java


注:本文中的android.nfc.tech.Ndef.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。