当前位置: 首页>>代码示例>>Java>>正文


Java NdefFormatable.format方法代码示例

本文整理汇总了Java中android.nfc.tech.NdefFormatable.format方法的典型用法代码示例。如果您正苦于以下问题:Java NdefFormatable.format方法的具体用法?Java NdefFormatable.format怎么用?Java NdefFormatable.format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.nfc.tech.NdefFormatable的用法示例。


在下文中一共展示了NdefFormatable.format方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

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

示例10: 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.format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。