Android Intent Set toByteArray(Intent intent)

Here you can find the source of toByteArray(Intent intent)

Description

to Byte Array

License

Apache License

Declaration

public static byte[] toByteArray(Intent intent) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import android.content.ContentValues;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcel;

import android.text.Spanned;
import android.text.TextUtils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Main {
    public static byte[] toByteArray(ContentValues contentValues) {
        Parcel obtain = Parcel.obtain();
        contentValues.writeToParcel(obtain, 0);
        byte[] byteArray = obtain.marshall();
        obtain.recycle();/*from   w ww.  j av a2 s .  c  o m*/
        return byteArray;
    }

    public static byte[] toByteArray(Bundle bundle) {
        Parcel obtain = Parcel.obtain();
        bundle.writeToParcel(obtain, 0);
        byte[] byteArray = obtain.marshall();
        obtain.recycle();
        return byteArray;
    }

    public static byte[] toByteArray(Intent intent) {
        Parcel obtain = Parcel.obtain();
        intent.writeToParcel(obtain, 0);
        byte[] byteArray = obtain.marshall();
        obtain.recycle();
        return byteArray;
    }

    public static byte[] toByteArray(Spanned spanned) {
        Parcel obtain = Parcel.obtain();
        TextUtils.writeToParcel(spanned, obtain, 0);
        byte[] byteArray = obtain.marshall();
        obtain.recycle();
        return byteArray;
    }

    public static byte[] toByteArray(Serializable serializable) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutput out = null;
        try {
            out = new ObjectOutputStream(bos);
            out.writeObject(serializable);
            byte[] bytes = bos.toByteArray();
            return bytes;
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        } finally {
            try {
                out.close();
                bos.close();
            } catch (IOException e) {
                //can be ignored;
            }

        }
    }
}

Related

  1. setBlankContentIntent(Context context, NotificationCompat.Builder builder)
  2. setNewTaskFlag(@Nonnull Intent intent)
  3. createCallIntent(String phoneNumber)
  4. extractSMSmessages(Intent intent)
  5. registerReceiver(Context c, BroadcastReceiver receiver, IntentFilter f, boolean local)