Citrin
Citrin

Reputation: 23

android how to add byte[] data to cloud firestore database

I have tried to upload my data of local database to Cloud Firestore database, and the data type of one field is byte[]. It can't be success or failure.

        Map<String, Object> setDetail = new HashMap<>();
        j = cursor.getColumnIndex("sound");
        byte[] sound = cursor.getBlob(j);
        setDetail.put("sound", sound);
        dbFire.collection("SetDetails").document(strWordID).set(setDetail)
                .addOnSuccessListener(new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                    }
                });

The debugger steps over this line dbFire.collection("SetDetails").document(strWordID).set(setDetail)

then jumps out to the last line of zzj.class

final class zzj implements Runnable {
zzj(zzi var1, Task var2) {
    this.zzm = var1;
    this.zzg = var2;
}

public final void run() {
    synchronized(zzi.zza(this.zzm)) {
        if (zzi.zzb(this.zzm) != null) {
            zzi.zzb(this.zzm).onComplete(this.zzg);
        }

    }
}

}

If I continue running, it will jump to this line of Looper.java

        final int thresholdOverride =
            SystemProperties.getInt("log.looper."
                    + Process.myUid() + "."
                    + Thread.currentThread().getName()
                    + ".slow", 0);

I have read documents, Bytes is one of data types that Cloud Firestore supports, so what's wrong with it. Could anyone help me? Thanks!

Upvotes: 2

Views: 1757

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317657

To write a byte array type field on Android, use Blob.fromBytes() to convert a byte array to a Blob object, then provide the Blob object to update() or set().

Upvotes: 5

Related Questions