下面列出了android.os.Parcel#writeByteArray ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void writeToParcel(Parcel dest, int flags) {
/*
NOTE: When adding fields in the process of updating this API, make sure to bump
{@link #PARCELABLE_VERSION}.
*/
dest.writeInt(PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = dest.dataPosition();
dest.writeInt(0);
int startPosition = dest.dataPosition();
// version 1
dest.writeInt(result);
// version 2
dest.writeByteArray(sessionKey);
dest.writeByteArray(decryptedSessionKey);
// Go back and write the size
int parcelableSize = dest.dataPosition() - startPosition;
dest.setDataPosition(sizePosition);
dest.writeInt(parcelableSize);
dest.setDataPosition(startPosition + parcelableSize);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(uuid);
dest.writeByte((byte) (isConfigured ? 1 : 0));
dest.writeString(nodeName);
dest.writeList(mAddedNetKeys);
dest.writeByteArray(mFlags);
dest.writeInt(unicastAddress);
dest.writeByteArray(deviceKey);
dest.writeValue(ttl);
dest.writeInt(sequenceNumber);
dest.writeValue(companyIdentifier);
dest.writeValue(productIdentifier);
dest.writeValue(versionIdentifier);
dest.writeValue(crpl);
dest.writeValue(nodeFeatures);
dest.writeMap(mElements);
dest.writeList(mAddedAppKeys);
dest.writeLong(mTimeStampInMillis);
dest.writeParcelable(mSeqAuth, flags);
dest.writeValue(secureNetworkBeaconSupported);
dest.writeParcelable(networkTransmitSettings, flags);
dest.writeParcelable(relaySettings, flags);
dest.writeInt((blackListed ? 1 : 0));
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mCustomLabel);
dest.writeString(mCategory);
dest.writeString(mIconUrl);
dest.writeString(mBannerUrl);
dest.writeByte((byte) (mUnique ? 1 : 0));
dest.writeString(mIntentUri);
if (mIconData == null) {
mIconData = new byte[0];
}
if (mBannerData == null) {
mBannerData = new byte[0];
}
dest.writeInt(mIconData.length);
dest.writeByteArray(mIconData);
dest.writeInt(mBannerData.length);
dest.writeByteArray(mBannerData);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
if (mDevice != null) {
dest.writeInt(1);
mDevice.writeToParcel(dest, flags);
} else {
dest.writeInt(0);
}
if (mScanRecord != null) {
dest.writeInt(1);
dest.writeByteArray(mScanRecord.getBytes());
} else {
dest.writeInt(0);
}
dest.writeInt(mRssi);
dest.writeLong(mTimestampNanos);
dest.writeInt(mEventType);
dest.writeInt(mPrimaryPhy);
dest.writeInt(mSecondaryPhy);
dest.writeInt(mAdvertisingSid);
dest.writeInt(mTxPower);
dest.writeInt(mPeriodicAdvertisingInterval);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(schemeIdUri);
dest.writeString(value);
dest.writeLong(presentationTimeUs);
dest.writeLong(durationMs);
dest.writeLong(id);
dest.writeByteArray(messageData);
}
public void writeToParcel(Parcel dest, int flags) {
/**
* NOTE: When adding fields in the process of updating this API, make sure to bump
* {@link #PARCELABLE_VERSION}.
*/
dest.writeInt(PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = dest.dataPosition();
dest.writeInt(0);
int startPosition = dest.dataPosition();
// version 1
dest.writeByteArray(keyData);
if (effectiveDate != null) {
dest.writeInt(1);
dest.writeLong(effectiveDate.getTime());
} else {
dest.writeInt(0);
}
dest.writeInt(preferEncrypt.ordinal());
// Go back and write the size
int parcelableSize = dest.dataPosition() - startPosition;
dest.setDataPosition(sizePosition);
dest.writeInt(parcelableSize);
dest.setDataPosition(startPosition + parcelableSize);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(uuid.getMostSignificantBits());
dest.writeLong(uuid.getLeastSignificantBits());
dest.writeString(licenseServerUrl);
dest.writeString(mimeType);
dest.writeByteArray(data);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.message);
dest.writeString(this.url);
dest.writeInt(this.code);
dest.writeByte(this.isRedirect ? (byte) 1 : (byte) 0);
dest.writeByte(this.isSuccessful ? (byte) 1 : (byte) 0);
dest.writeByte(this.isHttps ? (byte) 1 : (byte) 0);
dest.writeString(this.protocol);
dest.writeString(this.method);
dest.writeString(this.headers);
dest.writeByteArray(this.content);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(schemeIdUri);
dest.writeString(value);
dest.writeLong(durationMs);
dest.writeLong(id);
dest.writeByteArray(messageData);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(pictureType);
dest.writeString(mimeType);
dest.writeString(description);
dest.writeInt(width);
dest.writeInt(height);
dest.writeInt(depth);
dest.writeInt(colors);
dest.writeByteArray(pictureData);
}
private void writeNodeContents(Parcel dest) {
dest.writeLong(mId);
dest.writeString(mName);
dest.writeString(mUrl);
dest.writeInt(mType.ordinal());
dest.writeByteArray(mFavicon);
dest.writeByteArray(mThumbnail);
dest.writeLong(mParent != null ? mParent.mId : INVALID_BOOKMARK_ID);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(responderPackage);
dest.writeLong(responseId);
dest.writeInt(responseMessage != null ? 1 : 0);
if (responseMessage != null) {
dest.writeInt(responseMessage.length);
dest.writeByteArray(responseMessage);
}
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mimeType);
dest.writeString(filename);
dest.writeString(description);
dest.writeByteArray(data);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(key);
dest.writeInt(value.length);
dest.writeByteArray(value);
dest.writeInt(localeIndicator);
dest.writeInt(typeIndicator);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(colorSpace);
dest.writeInt(colorRange);
dest.writeInt(colorTransfer);
Util.writeBoolean(dest, hdrStaticInfo != null);
if (hdrStaticInfo != null) {
dest.writeByteArray(hdrStaticInfo);
}
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(resultCode);
out.writeStrongBinder(token);
out.writeLong(operationHandle);
out.writeInt(inputConsumed);
out.writeByteArray(output);
outParams.writeToParcel(out, flags);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(schemeIdUri);
dest.writeString(value);
dest.writeLong(durationMs);
dest.writeLong(id);
dest.writeByteArray(messageData);
}
public Tag mockTag(String technology) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
// For future reference
// Parameters :
byte[] b = {0x8};
String ndefClass = "android.nfc.tech.Ndef";
// FieldName which marks the capacity of the tag
String extraNdefMaxlength = (String) Class.forName(ndefClass).getField("EXTRA_NDEF_MAXLENGTH").get(null);
// FieldName which marks the tags writability
String cardWritableStateField = (String) Class.forName(ndefClass).getField("EXTRA_NDEF_CARDSTATE").get(null);
// Field to mark tag R/W
int cardWritable = Class.forName(ndefClass).getField("NDEF_MODE_READ_WRITE").getInt(null);
Bundle techExtras = new Bundle();
techExtras.putInt(extraNdefMaxlength, 2048);
techExtras.putInt(cardWritableStateField, cardWritable);
Bundle[] extras = {techExtras};
int[] technologies = {TagTechnology.class.getField(technology.toUpperCase()).getInt(null)}; //https://android.googlesource.com/platform/frameworks/base.git/+/android-4.3_r2/core/java/android/nfc/tech/TagTechnology.java
// https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/nfc/Tag.java :376
Parcel parcel = Parcel.obtain();
parcel.writeByteArray(b); //Sets the ID
parcel.writeIntArray(technologies); // Sets the technology to NDEF
parcel.writeArray(extras); // Needed to set properties for NDEF tag
parcel.writeInt(1); // Service handle
parcel.writeInt(1); // Indicating a mock
return Tag.CREATOR.createFromParcel(parcel);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(id);
dest.writeByteArray(data);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(mId);
dest.writeByteArray(mEvent.getBytes());
}