Code example for NdefMessage

Methods: toByteArray

0
			mAdapter.disableForegroundDispatch(this);
		} 
	} 
 
	private void write(Tag tag) throws IOException, FormatException {
		NdefMessage rawMessage = new NdefMessage(
				NdefRecord.createUri(mTargetUrl));
		NdefFormatable format = NdefFormatable.get(tag);
		if (format != null) {
			Log.d(TAG, "Write unformatted tag");
			try { 
				format.connect();
				format.format(rawMessage);
			} catch (Exception e) {
			} finally { 
				try { 
					format.close();
				} catch (IOException e) {
				} 
			} 
			Log.d(TAG, "Cannot write unformatted tag");
		} else { 
			Ndef ndef = Ndef.get(tag);
			if (ndef != null) {
				try { 
					Log.d(TAG, "Write formatted tag");
 
					ndef.connect();
					if (!ndef.isWritable()) {
						Log.d(TAG, "Tag is not writeable");
					} 
 
					if (ndef.getMaxSize() < rawMessage.toByteArray().length) {
						Log.d(TAG,
								"Tag size is too small, have " 
										+ ndef.getMaxSize() + ", need "
										+ rawMessage.toByteArray().length);
					} 
					ndef.writeNdefMessage(rawMessage);
				} catch (Exception e) {
				} finally { 
					try {