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


Java NdefFormatable.get方法代碼示例

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


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

示例1: formatTag

import android.nfc.tech.NdefFormatable; //導入方法依賴的package包/類
private void formatTag(Tag tag, NdefMessage ndefMessage)
{
    try
    {
        NdefFormatable ndefFormatable = NdefFormatable.get(tag);

        if (ndefFormatable == null)
        {
            Toast.makeText(this, "Tag is not formatable", Toast.LENGTH_LONG).show();
        }

        ndefFormatable.connect();
        ndefFormatable.format(ndefMessage);
        ndefFormatable.close();
    }
    catch (Exception e)
    {
        Log.e("formatTag", e.getMessage());
    }
}
 
開發者ID:ThomasDelaney,項目名稱:TapIn,代碼行數:21,代碼來源:add3.java

示例2: writeTAG

import android.nfc.tech.NdefFormatable; //導入方法依賴的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

示例3: writeTag

import android.nfc.tech.NdefFormatable; //導入方法依賴的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

示例4: writeTag

import android.nfc.tech.NdefFormatable; //導入方法依賴的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

示例5: formatTag

import android.nfc.tech.NdefFormatable; //導入方法依賴的package包/類
private void formatTag(Tag tag, NdefMessage ndefMessage) {
    try{
        NdefFormatable ndefFormatable = NdefFormatable.get(tag);

        if(ndefFormatable == null) {
            Toast.makeText(this, "Tag is not NdefFormatable!!", Toast.LENGTH_SHORT).show();
            return;
        }

        ndefFormatable.connect();
        ndefFormatable.format(ndefMessage);
        ndefFormatable.close();

        Toast.makeText(this, "Tag Written!! :) ", Toast.LENGTH_SHORT).show();

    } catch (Exception e) {
        Log.e("formatTag", e.getMessage());
    }
}
 
開發者ID:JimSeker,項目名稱:nfc,代碼行數:20,代碼來源:MainActivity.java

示例6: writeNFCTag

import android.nfc.tech.NdefFormatable; //導入方法依賴的package包/類
/**
 * 往標簽寫數據的方法
 *
 * @param tag
 */
public void writeNFCTag(Tag tag) {
    if (tag == null) {
        return;
    }
    NdefMessage ndefMessage = new NdefMessage(new NdefRecord[]{NdefRecord
            .createApplicationRecord(mPackageName)});
    //轉換成字節獲得大小
    int size = ndefMessage.toByteArray().length;
    try {
        //2.判斷NFC標簽的數據類型(通過Ndef.get方法)
        Ndef ndef = Ndef.get(tag);
        //判斷是否為NDEF標簽
        if (ndef != null) {
            ndef.connect();
            //判斷是否支持可寫
            if (!ndef.isWritable()) {
                return;
            }
            //判斷標簽的容量是否夠用
            if (ndef.getMaxSize() < size) {
                return;
            }
            //3.寫入數據
            ndef.writeNdefMessage(ndefMessage);
            Toast.makeText(this, "寫入成功", Toast.LENGTH_SHORT).show();
        } else { //當我們買回來的NFC標簽是沒有格式化的,或者沒有分區的執行此步
            //Ndef格式類
            NdefFormatable format = NdefFormatable.get(tag);
            //判斷是否獲得了NdefFormatable對象,有一些標簽是隻讀的或者不允許格式化的
            if (format != null) {
                //連接
                format.connect();
                //格式化並將信息寫入標簽
                format.format(ndefMessage);
                Toast.makeText(this, "寫入成功", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(this, "寫入失敗", Toast.LENGTH_SHORT).show();
            }
        }
    } catch (Exception e) {
    }
}
 
開發者ID:jopenbox,項目名稱:android-nfc,代碼行數:48,代碼來源:RunAppActivity.java

示例7: doInBackground

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

    Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    NdefMessage message = this.tag.encode();

    if (tag != null) {
        try {
            Ndef ndefTag = Ndef.get(tag);
            if (ndefTag == null) {
                NdefFormatable ndefForm = NdefFormatable.get(tag);
                if (ndefForm != null) {
                    ndefForm.connect();
                    ndefForm.format(message);
                    ndefForm.close();
                }
            }
            else {
                ndefTag.connect();
                ndefTag.writeNdefMessage(message);
                ndefTag.close();
            }
            return true;
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }

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

示例8: create

import android.nfc.tech.NdefFormatable; //導入方法依賴的package包/類
/**
 * Factory method that creates NfcTagHandler for a given NFC Tag.
 *
 * @param tag @see android.nfc.Tag
 * @return NfcTagHandler or null when unsupported Tag is provided.
 */
public static NfcTagHandler create(Tag tag) {
    if (tag == null) return null;

    Ndef ndef = Ndef.get(tag);
    if (ndef != null) return new NfcTagHandler(ndef, new NdefHandler(ndef));

    NdefFormatable formattable = NdefFormatable.get(tag);
    if (formattable != null) {
        return new NfcTagHandler(formattable, new NdefFormattableHandler(formattable));
    }

    return null;
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:20,代碼來源:NfcTagHandler.java

示例9: writeToTag

import android.nfc.tech.NdefFormatable; //導入方法依賴的package包/類
@Override
public boolean writeToTag(NdefMessage message, Tag tag) throws FormatException, ReadOnlyTagException, InsufficientCapacityException {
    Ndef ndef = Ndef.get(tag);
    NdefFormatable formatable = NdefFormatable.get(tag);

    boolean result;
    if (readOnly) {
        result = writeToNdefAndMakeReadonly(message, ndef) || writeToNdefFormatableAndMakeReadonly(message, formatable);
    } else {
        result = writeToNdef(message, ndef) || writeToNdefFormatable(message, formatable);
    }

    readOnly = false;
    return result;
}
 
開發者ID:appfoundry,項目名稱:android-nfc-lib,代碼行數:16,代碼來源:WriteUtilityImpl.java

示例10: writeNFCTag

import android.nfc.tech.NdefFormatable; //導入方法依賴的package包/類
/**
 * 往標簽寫數據的方法
 *
 * @param tag
 */
public void writeNFCTag(Tag tag) {
    if (tag == null) {
        return;
    }
    NdefMessage ndefMessage = new NdefMessage(new NdefRecord[]{NdefRecord
            .createUri(Uri.parse("http://www.baidu.com"))});
    //轉換成字節獲得大小
    int size = ndefMessage.toByteArray().length;
    try {
        //2.判斷NFC標簽的數據類型(通過Ndef.get方法)
        Ndef ndef = Ndef.get(tag);
        //判斷是否為NDEF標簽
        if (ndef != null) {
            ndef.connect();
            //判斷是否支持可寫
            if (!ndef.isWritable()) {
                return;
            }
            //判斷標簽的容量是否夠用
            if (ndef.getMaxSize() < size) {
                return;
            }
            //3.寫入數據
            ndef.writeNdefMessage(ndefMessage);
            Toast.makeText(this, "寫入成功", Toast.LENGTH_SHORT).show();
        } else { //當我們買回來的NFC標簽是沒有格式化的,或者沒有分區的執行此步
            //Ndef格式類
            NdefFormatable format = NdefFormatable.get(tag);
            //判斷是否獲得了NdefFormatable對象,有一些標簽是隻讀的或者不允許格式化的
            if (format != null) {
                //連接
                format.connect();
                //格式化並將信息寫入標簽
                format.format(ndefMessage);
                Toast.makeText(this, "寫入成功",
                        Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(this, "寫入失敗", Toast.LENGTH_SHORT).show();
            }
        }
    } catch (Exception e) {
    }
}
 
開發者ID:jopenbox,項目名稱:android-nfc,代碼行數:49,代碼來源:RunUrlActivity.java

示例11: formatTag

import android.nfc.tech.NdefFormatable; //導入方法依賴的package包/類
private void formatTag(Tag tag, NdefMessage ndefMessage) {
    try {

        NdefFormatable ndefFormatable = NdefFormatable.get(tag);

        if (ndefFormatable == null) {
            Toast.makeText(this, "Tag is not ndef formatable!", Toast.LENGTH_SHORT).show();
            return;
        }


        ndefFormatable.connect();
        ndefFormatable.format(ndefMessage);
        ndefFormatable.close();

        Toast.makeText(this, "Tag writen!", Toast.LENGTH_SHORT).show();

    } catch (Exception e) {
        Log.e("formatTag", e.getMessage());
    }

}
 
開發者ID:tekesan,項目名稱:TraiNFCUI,代碼行數:23,代碼來源:Tap.java

示例12: writeNFCTag

import android.nfc.tech.NdefFormatable; //導入方法依賴的package包/類
private void writeNFCTag(Tag tag){
	if(tag == null){
		return;
	}
	
	NdefMessage ndefMessage = new NdefMessage( new NdefRecord[]{NdefRecord.createUri(Uri.parse("http://www.baidu.com"))} );
	int size = ndefMessage.toByteArray().length;
	
	try {
		Ndef ndef = Ndef.get(tag);
		//���ж�һ�������ǩ�Dz���NDEF��
		if(ndef != null){ //�����NDEF��ʽ��
			ndef.connect();
			//�����ж������ǩ�Ƿ��ǿ�д��
			if( ! ndef.isWritable()){ //����Dz���д�ģ�ֱ�ӾͿ��Խ�����
				Toast.makeText(this , "��NFC��ǩ����д!" , Toast.LENGTH_SHORT).show();
				return;
			}
			//�����жϵ�ǰ��ǩ����������Ƿ���װ������Ҫд�����Ϣ
			if(ndef.getMaxSize() < size){
				Toast.makeText(this , "��NFC��ǩ������д����̫С!" , Toast.LENGTH_SHORT).show();
				return;
			}
			//����Ϊֹ���Ϳ��Է��ĵİѶ���д��NFC��ǩ����
			ndef.writeNdefMessage(ndefMessage);
			Toast.makeText(this , "NFC��ǩд�����ݳɹ�" , Toast.LENGTH_SHORT).show();
		}
		else{ //�������NDEF��ʽ��
			//���Խ������NDEF��ǩ��ʽ����NDEF��ʽ��
			NdefFormatable format = NdefFormatable.get(tag);
			//��Ϊ��Щ��ǩ��ֻ���ģ�����������Ҫ�ж�һ��
			//���format��Ϊnull����ʾ�����ǩ�ǿ��Խ��ܸ�ʽ����
			if(format != null){
				format.connect();
				format.format(ndefMessage); //ͬʱ����˸�ʽ����д����Ϣ�IJ���
				Toast.makeText(this , "NFC��ǩ��ʽ��д��ɹ�" , Toast.LENGTH_SHORT).show();
			}
			else{
				Toast.makeText(this , "��NFC��ǩ�޷�����ʽ��" , Toast.LENGTH_SHORT).show();
			}
		}
	} 
	catch (Exception e) {
		Toast.makeText(this , "�޷���ȡ��NFC��ǩ" , Toast.LENGTH_SHORT).show();
	}
}
 
開發者ID:ZhaoYukai,項目名稱:NFCApp2,代碼行數:47,代碼來源:AutoOpenUriActivity.java


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