Payload Manager错误附近的连接

时间:2018-03-02 15:15:54

标签: java android google-contacts google-nearby parcelfiledescriptor

我使用ParcelFileDescriptor向连接的设备发送数据帧,但是当我检查错误日志时,我看到了这个错误。

03-03 02:06:12.896 4047-4133/shaveyourneck.syn.app.com.shaveyourneck W/NearbyConnections: Exception copying stream for Payload -7679084608943108956
                                                                                      java.io.IOException: File descriptor closed
                                                                                          at libcore.io.Posix.readBytes(Native Method)
                                                                                          at libcore.io.Posix.read(Posix.java:147)
                                                                                          at libcore.io.BlockGuardOs.read(BlockGuardOs.java:230)
                                                                                          at libcore.io.IoBridge.read(IoBridge.java:512)
                                                                                          at java.io.FileInputStream.read(FileInputStream.java:177)
                                                                                          at com.google.android.gms.common.util.zzn.zza(Unknown Source)
                                                                                          at com.google.android.gms.internal.zzcon.run(Unknown Source)
                                                                                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                                                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                                          at java.lang.Thread.run(Thread.java:818)


03-03 02:06:12.901 1118-4134/? E/NearbyConnections: PayloadManager short-circuiting Payload (id:-7679084608943108956 type:STREAM) after sending 0 bytes because we failed to detach the next chunk.
                                                java.io.IOException: Error status received for Payload (id:-7679084608943108956 type:STREAM)
                                                    at yll.c(:com.google.android.gms@11975230:15)
                                                    at yme.a(:com.google.android.gms@11975230:29)
                                                    at yme.call(:com.google.android.gms@11975230)
                                                    at yjd.a(:com.google.android.gms@11975230:4)
                                                    at ymd.run(:com.google.android.gms@11975230:46)
                                                    at mwh.run(:com.google.android.gms@11975230:26)
                                                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                    at nbq.run(:com.google.android.gms@11975230)
                                                    at java.lang.Thread.run(Thread.java:818)

这是我的代码段:

 private void initFramesToBeSendCallback() {
    // this is where i initiate the parcelfiledescriptor to the outputstream in the parcelfiledescriptor[1]

    outputStream = new ParcelFileDescriptor.AutoCloseOutputStream(writePfd);

     //  Camera surface callback which returns camera frames data that i use to send write it in outputstream and send to connected device
    surfaceHolder.setFramesToBeRetrieveListener(new CustomSurfaceHolder.OnCaptureFramesToBeSendCallback() {
        @Override
        public void getCurrentData(byte[] bytes) {
            if (isRecording) {
                Log.e(TAG, "initFramesToBeSendCallback RECORDING, will send data!");
                send1stArrayOfParcelFileDescriptor(readPfd);
                sendFramesOfImages(bytes);
            } else {
                Log.e(TAG, "initFramesToBeSendCallback NOT RECORDING");
            }

        }
    });
}




 private void send1stArrayOfParcelFileDescriptor(ParcelFileDescriptor fd) {
    Nearby.Connections.sendPayload(client, endpointString, Payload.fromStream(fd))
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if (status.isSuccess() || status.getStatusCode() == 0) {
                        Log.e(TAG, "onResult: STREAM DATA SUCCESS send1stArrayOfParcelFileDescriptor");
                    } else {
                        Log.e(TAG, "onResult: FAILED TO SEND STREAM DATA ERROR send1stArrayOfParcelFileDescriptor CODE: " + status.getStatusCode());
                    }
                }
            });
}


private void sendFramesOfImages(byte[] bytes) {
    byteRef = bytes;

    new Thread(new Runnable() {
        @Override
        public void run() {

            try {
                outputStream.write(byteRef, 0, byteRef.length);
                outputStream.flush();
            } catch (IOException e) {
                e.printStackTrace();
                Log.e(TAG, "sendFramesOfImages: EXCEPTION SENDING PARCELFILE DESCRIPTOR[1] " + e.getMessage());
            }

        }
    }).start();

}

我不知道导致的错误是什么以及其背后的原因。我无法在谷歌搜索中找到任何相关的错误。我希望Google Devs的某些人可以帮助我。感谢

0 个答案:

没有答案