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


Java Ndef.close方法代码示例

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


在下文中一共展示了Ndef.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

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

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

import android.nfc.tech.Ndef; //导入方法依赖的package包/类
private void writeToNfc(Ndef ndef, String message){

        mTvMessage.setText(getString(R.string.message_write_progress));
        if (ndef != null) {

            try {
                ndef.connect();
                NdefRecord mimeRecord = NdefRecord.createMime("text/plain", message.getBytes(Charset.forName("US-ASCII")));
                ndef.writeNdefMessage(new NdefMessage(mimeRecord));
                ndef.close();
                //Write Successful
                mTvMessage.setText(getString(R.string.message_write_success));

            } catch (IOException | FormatException e) {
                e.printStackTrace();
                mTvMessage.setText(getString(R.string.message_write_error));

            } finally {
                mProgress.setVisibility(View.GONE);
            }

        }
    }
 
开发者ID:Learn2Crack,项目名称:android-nfc-tag-read-write,代码行数:24,代码来源:NFCWriteFragment.java

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

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

示例6: 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;
  }
  try {
    NdefMessage msg = new NdefMessage(
        new NdefRecord[] { NdefRecord.createMime(
            "application/pubk.com.sawyer.easypgp", publicKeyBytes) });
    ndef.connect();
    ndef.writeNdefMessage(msg);
    ndef.close();
    return "Success";
  } catch (Exception e) {
    e.printStackTrace();
  }

  return null;
}
 
开发者ID:masstamike,项目名称:easypgp,代码行数:24,代码来源:NfcActivity.java

示例7: writableTag

import android.nfc.tech.Ndef; //导入方法依赖的package包/类
private boolean writableTag(Tag tag) {

		try {
			Ndef ndef = Ndef.get(tag);
			if (ndef != null) {
				ndef.connect();
				if (!ndef.isWritable()) {
					ToastUtils.makeWarningToast(this, "Tag is Read-Only.");

					ndef.close();
					return false;
				}
				ndef.close();
				return true;
			}
		} catch (Exception e) {
			Logger.e(TAG, e.getLocalizedMessage());
			ToastUtils.makeWarningToast(this, "Failed to Read Tag");
		}

		return false;
	}
 
开发者ID:MikeFot,项目名称:Android--Event-Triggered-Skype-Caller,代码行数:23,代码来源:WriteNFCActivity.java

示例8: writeMessage

import android.nfc.tech.Ndef; //导入方法依赖的package包/类
private void writeMessage(Tag tag, NdefMessage ndefMessage)
{
    try
    {
        if (tag == null)
        {
            Toast.makeText(this, "An Error has Occurred, Please Try Again", Toast.LENGTH_LONG).show();
        }

        Ndef ndef = Ndef.get(tag);

        if (ndef == null)
        {
            formatTag(tag, ndefMessage);
        }
        else
        {
            ndef.connect();

            if (!ndef.isWritable())
            {
                Toast.makeText(this, "Tag is not Writable", Toast.LENGTH_LONG).show();
                ndef.close();
                return;
            }

            ndef.writeNdefMessage(ndefMessage);
            ndef.close();
        }
    }
    catch (Exception e)
    {
        Log.e("writeMessage", e.getMessage());
    }
}
 
开发者ID:ThomasDelaney,项目名称:TapIn,代码行数:36,代码来源:add3.java

示例9: getNdefRecordCount

import android.nfc.tech.Ndef; //导入方法依赖的package包/类
private DataReply getNdefRecordCount() {
    DataReply dataReply = new DataReply();
    int recordCount = 0;
    if (currentTag != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
            Ndef ndef = Ndef.get(currentTag);

            if (ndef != null) {
                if (ndef.getCachedNdefMessage() != null)
                    recordCount = ndef.getCachedNdefMessage().getRecords().length;
                else
                    recordCount = 0;
            } else {
                dataReply.setError(TAG_READING_ERROR);
                return dataReply;
            }
            try {
                if (ndef != null) ndef.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    if (recordCount > 256) {
        dataReply.setError(INDEX_OUT_OF_BOUNDS);
        recordCount = 256;
    }
    dataReply.setIntegerData(recordCount);
    return dataReply;
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:31,代码来源:NfcShield.java

示例10: getNdefRecordTypeLength

import android.nfc.tech.Ndef; //导入方法依赖的package包/类
private DataReply getNdefRecordTypeLength(int recordNumber) {
    DataReply dataReply = new DataReply();
    int length = 0;
    if (currentTag != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
            Ndef ndef = Ndef.get(currentTag);
            if (ndef != null) {
                if (ndef.getCachedNdefMessage() != null)
                    if (ndef.getCachedNdefMessage().getRecords().length > recordNumber) {
                        NdefRecord record = ndef.getCachedNdefMessage().getRecords()[recordNumber];
                        length = record.getType().length;
                    } else {
                        dataReply.setError(RECORD_NOT_FOUND);
                        return dataReply;
                    }
                else {
                    dataReply.setError(RECORD_NOT_FOUND);
                    return dataReply;
                }
            } else {
                dataReply.setError(TAG_READING_ERROR);
                return dataReply;
            }
            try {
                if (ndef != null) ndef.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    dataReply.setIntegerData(length);
    return dataReply;
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:34,代码来源:NfcShield.java

示例11: getNdefRecordDataLength

import android.nfc.tech.Ndef; //导入方法依赖的package包/类
private DataReply getNdefRecordDataLength(int recordNumber) {
    DataReply dataReply = new DataReply();
    int length = 0;
    if (currentTag != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
            Ndef ndef = Ndef.get(currentTag);
            if (ndef != null) {
                if (ndef.getCachedNdefMessage() != null)
                    if (ndef.getCachedNdefMessage().getRecords().length > recordNumber) {
                        NdefRecord record = ndef.getCachedNdefMessage().getRecords()[recordNumber];
                        length = record.getPayload().length;
                    } else {
                        dataReply.setError(RECORD_NOT_FOUND);
                        return dataReply;
                    }
                else {
                    dataReply.setError(RECORD_NOT_FOUND);
                    return dataReply;
                }
            } else {
                dataReply.setError(TAG_READING_ERROR);
                return dataReply;
            }
            try {
                if (ndef != null) ndef.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    dataReply.setIntegerData(length);
    return dataReply;
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:34,代码来源:NfcShield.java

示例12: writeNdefMessage

import android.nfc.tech.Ndef; //导入方法依赖的package包/类
private void writeNdefMessage(Tag tag, NdefMessage ndefMessage) {

        try {

            if (tag == null) {
                Toast.makeText(this, "Tag object cannot be null", Toast.LENGTH_SHORT).show();
                return;
            }

            Ndef ndef = Ndef.get(tag);

            if (ndef == null) {
                // format tag with the ndef format and writes the message.
                formatTag(tag, ndefMessage);
            } else {
                ndef.connect();

                if (!ndef.isWritable()) {
                    Toast.makeText(this, "Tag is not writable!", Toast.LENGTH_SHORT).show();

                    ndef.close();
                    return;
                }

                ndef.writeNdefMessage(ndefMessage);
                ndef.close();

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

            }

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

    }
 
开发者ID:tekesan,项目名称:TraiNFCUI,代码行数:37,代码来源:Tap.java

示例13: doInBackground

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

示例14: readFromNFC

import android.nfc.tech.Ndef; //导入方法依赖的package包/类
private void readFromNFC(Ndef ndef) {

        try {
            ndef.connect();
            NdefMessage ndefMessage = ndef.getNdefMessage();
            String message = new String(ndefMessage.getRecords()[0].getPayload());
            Log.d(TAG, "readFromNFC: "+message);
            mTvMessage.setText(message);
            ndef.close();

        } catch (IOException | FormatException e) {
            e.printStackTrace();

        }
    }
 
开发者ID:Learn2Crack,项目名称:android-nfc-tag-read-write,代码行数:16,代码来源:NFCReadFragment.java

示例15: write

import android.nfc.tech.Ndef; //导入方法依赖的package包/类
private void write(String text, Tag tag) throws IOException, FormatException {
    /*
     http://stackoverflow.com/questions/11427997/android-app-to-add-mutiple-record-in-nfc-tag
      */
    // We want to include a reference to the app, for those who don't have one.
    // This way, their phones will open this app when a tag encoded with this app is used.
    String arrPackageName = "com.briankhuu.nfcmessageboard";
    final int AAR_RECORD_BYTE_LENGTH = 50; // I guess i suck at byte counting. well at least this should still work. This approach does lead to wasted space however.
    //infoMsg = "\n\n---\n To post here. Use the "NFC Messageboard" app: https://play.google.com/store/search?q=NFC%20Message%20Board ";


    // Trim to size (for now this is just a dumb trimmer...) (Later on, you want to remove whole post first
    // Seem that header and other things takes 14 chars. For safety. Lets just remove 20.
    // 0 (via absolute value) < valid entry size < Max Tag size
    final int NDEF_RECORD_HEADER_SIZE = 6;
    final int NDEF_STRING_PAYLOAD_HEADER_SIZE = 4;
    int maxTagByteLength = Math.abs(tag_size - NDEF_RECORD_HEADER_SIZE - NDEF_STRING_PAYLOAD_HEADER_SIZE - AAR_RECORD_BYTE_LENGTH);
    if (text.length() >= maxTagByteLength ){ // Write like normal if content to write will fit without modification
        // Else work out what to remove. For now, just do a dumb trimming. // Unicode characters may take more than 1 byte.
        text = truncateWhenUTF8(text, maxTagByteLength);
    }

    // Write tag
    //NdefRecord[] records = { createRecord(text), aarNdefRecord };
    NdefMessage message = new NdefMessage(new NdefRecord[]{
            createRecord(text)
            ,NdefRecord.createApplicationRecord(arrPackageName)
    });
    Ndef ndef = Ndef.get(tag);
    ndef.connect();
    ndef.writeNdefMessage(message);
    ndef.close();
}
 
开发者ID:mofosyne,项目名称:NFCMessageBoard,代码行数:34,代码来源:MainScreen.java


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