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


Java Ndef.getMaxSize方法代碼示例

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


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

示例3: 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

示例4: onCreate

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_show_nfctag_content);
	mTagContent = (TextView) findViewById(R.id.textview_tag_content);

	mDetectedTag = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);

	Ndef ndef = Ndef.get(mDetectedTag);

	mTagText = ndef.getType() + "\nmax size:" + ndef.getMaxSize()
			+ "bytes\n\n";

	readNFCTag();

	mTagContent.setText(mTagText);
}
 
開發者ID:384401056,項目名稱:itheima,代碼行數:19,代碼來源:ShowNFCTagContentActivity.java

示例5: writeNfcTag

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
private void writeNfcTag(@NonNull final Tag tag) {
    final Ndef ndef = Ndef.get(tag);

    if (ndef == null) {
        showWriteError(getText(R.string.nfc_error_no_ndef));
        return;
    }

    if (!ndef.isWritable()) {
        showWriteError(getText(R.string.nfc_error_not_writable));
        return;
    }

    final NdefMessage message = NdefUtils.toNdefMessage(mPassword);

    final int messageLength = message.getByteArrayLength();
    final int maxSize = ndef.getMaxSize();

    if (messageLength > maxSize) {
        showWriteError(
                getString(R.string.nfc_error_not_enough_space_format, messageLength, maxSize));
        return;
    }

    new TagWriteTask(this).execute(new TagWriteParam(ndef, message));
}
 
開發者ID:xxv,項目名稱:SuperGenPass,代碼行數:27,代碼來源:NfcWriteFragment.java

示例6: writeNFCTag

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

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
@Override
public void onNewIntent(Intent intent) {
    //獲取Tag對象
    Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    //獲取Ndef的實例
    Ndef ndef = Ndef.get(detectedTag);
    mTagText = ndef.getType() + "\n max size:" + ndef.getMaxSize() + " bytes\n\n";
    readNfcTag(intent);
    mNfcText.setText(mTagText);
}
 
開發者ID:jopenbox,項目名稱:android-nfc,代碼行數:11,代碼來源:ReadUriActivity.java

示例8: onNewIntent

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
@Override
public void onNewIntent(Intent intent) {
    //1.獲取Tag對象
    Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    //2.獲取Ndef的實例
    Ndef ndef = Ndef.get(detectedTag);
    mTagText = ndef.getType() + "\nmaxsize:" + ndef.getMaxSize() + "bytes\n\n";
    readNfcTag(intent);
    mNfcText.setText(mTagText);
}
 
開發者ID:jopenbox,項目名稱:android-nfc,代碼行數:11,代碼來源:ReadTextActivity.java

示例9: writeNFCTag

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

示例10: onNewIntent

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
/**
 * Listen to NFC incomming data
 */
@Override
public void onNewIntent(Intent intent) {
    MLog.d(TAG, "New intent " + intent);

    if (intent.getAction() != null) {
        MLog.d(TAG, "Discovered tag with intent: " + intent);

        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        String nfcID = StrUtils.bytetostring(tag.getId());

        // if there is a message waiting to be written
        if (PNfc.nfcMsg != null) {
            MLog.d(TAG, "->" + PNfc.nfcMsg);
            PNfc.writeTag(this, tag, PNfc.nfcMsg);
            if (onNFCWrittenListener != null) onNFCWrittenListener.onNewTag();
            onNFCWrittenListener = null;
            PNfc.nfcMsg = null;

        // read the nfc tag info
        } else {
            // get NDEF tag details
            Ndef ndefTag = Ndef.get(tag);
            if (ndefTag == null) {
                return;
            }

            int size = ndefTag.getMaxSize(); // tag size
            boolean writable = ndefTag.isWritable(); // is tag writable?
            String type = ndefTag.getType(); // tag type

            String nfcMessage = "";

            // get NDEF message details
            NdefMessage ndefMesg = ndefTag.getCachedNdefMessage();
            if (ndefMesg != null) {
                NdefRecord[] ndefRecords = ndefMesg.getRecords();
                int len = ndefRecords.length;
                String[] recTypes = new String[len]; // will contain the
                // NDEF record types
                String[] recPayloads = new String[len]; // will contain the
                // NDEF record types
                for (int i = 0; i < len; i++) {
                    recTypes[i] = new String(ndefRecords[i].getType());
                    recPayloads[i] = new String(ndefRecords[i].getPayload());
                    MLog.d(TAG, "qq " + i + " " + recTypes[i] + " " + recPayloads[i]);

                }
                nfcMessage = recPayloads[0];
            }
            if (onNFCListener != null) onNFCListener.onNewTag(nfcID, nfcMessage);
        }
    }
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:57,代碼來源:AppRunnerActivity.java

示例11: writeNFCTag

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

示例12: handleIntent

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
private void handleIntent(Intent intent) {
    /*
    *   Else just read tag as usual.
    * */
    /*
        This detects the intent and calls an nfc reading task
        I modified this to keep the tag object exposed in this class.
        This is since we will want to write to the same tag later.
     */
    String action = intent.getAction();

    // We want to read only valid html tags
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
    {
        boolean mime_type_found = false;
        String type = intent.getType();

        if (MIME_TEXT_HTML.equals(type))
        {
            Toast.makeText(this, "Reading Html Tag", Toast.LENGTH_SHORT).show();
            tag_compression_mode = CompressionMode_Enum.NONE;
            mime_type_found = true;
        }
        else
        if (MIME_TEXT_HTML_GZIP.equals(type))
        {
            Toast.makeText(this, "Reading Gzipped Html Tag", Toast.LENGTH_SHORT).show();
            tag_compression_mode = CompressionMode_Enum.GZIP;
            mime_type_found = true;
        }


        // if plain/html
        if (mime_type_found) {
            tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
            new NdefReaderTask().execute(tag);
        } else {
            //Log.d(TAG, "Wrong mime type: " + type);
        }
    }
    else
    {
        Log.e(LOGGER_TAG, "Skipping Tag as it is not NDEF");
    }

    /*
        So some useful tag info
        http://stackoverflow.com/questions/9971820/how-to-read-detected-nfc-tag-ndef-content-details-in-android
     */
    if (tag != null) {
        //Toast.makeText(this, "Reading Tag Info", Toast.LENGTH_SHORT).show();
        // get NDEF tag details
        Ndef ndefTag = Ndef.get(tag);

        tag_writable = ndefTag.isWritable(); // is tag writable?

        // get NDEF message details
        NdefMessage ndefMesg = ndefTag.getCachedNdefMessage();
        NdefRecord[] ndefRecords = ndefMesg.getRecords();
        int len = ndefRecords.length;
        recTypes = new String[len];     // will contain the NDEF record types
        for (int i = 0; i < len; i++) {
            recTypes[i] = new String(ndefRecords[i].getType());
        }

        // Get Tag ID
        tagID_string = bytesToHex(tag.getId());
        tag_size = ndefTag.getMaxSize();     // tag size
        tag_type = ndefTag.getType();         // tag type
    }
}
 
開發者ID:mofosyne,項目名稱:NFCMessageBoard,代碼行數:72,代碼來源:ReadHtmlTags.java

示例13: onCreate

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_show_nfctext);
	
	tv_context = (TextView) findViewById(R.id.tv_context);
	tv_text = (TextView) findViewById(R.id.tv_text);
	
	myTag = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);
	
	Ndef ndef = Ndef.get(myTag);
	
	mTagText = "標簽類型:"+ndef.getType()+"\n最大容量:"+ndef.getMaxSize()+"bytes\n";
	
	readNFCTag();
	
	tv_context.setText(mTagText);
}
 
開發者ID:384401056,項目名稱:itheima,代碼行數:19,代碼來源:ShowNFCTextActivity.java


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