onPayloadReceived Nearby connections 2.0不接收文件有效负载

时间:2017-11-02 14:18:47

标签: google-play-services google-nearby

@Override
public void onPayloadReceived(String endpointId, Payload payload) {
  if (payload.getType() == Payload.Type.BYTES) {
    String payloadFilenameMessage = new String(payload.asBytes(), "UTF-8");
    addPayloadFilename(payloadFilenameMessage);
  } else if (payload.getType() == Payload.Type.FILE) {
    // Add this to our tracking map, so that we can retrieve the payload later.
    incomingPayloads.add(payload.getId(), payload);
  }
}

问题是payload.getType()== Payload.Type.FILE条件永远不会成立,只有Payload.Type.BYTES条件为真。

sendPayload()代码段来自Exchange Data API page

// The URI of the file selected by the user.
Uri uri = resultData.getData();

// Open the ParcelFileDescriptor for this URI with read access.
ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "r");
Payload filePayload = Payload.fromFile(pfd);

// Finally, send the file payload.
Nearby.Connections.sendPayload(endpointId, filePayload); 

我知道这是重复的,但我没有在网上找到任何有用的解决方案(关于发送文件)至少要比较我的代码(未完成的媒体文章(文本),对讲机应用程序(流)和片段来自文件)

这里有来源https://github.com/salexwm/FilesExchange

1 个答案:

答案 0 :(得分:0)

看起来发送文件有效负载的代码已在https://github.com/salexwm/FilesExchange/blob/master/app/src/main/java/com/test/filesexchange/ShareService.java#L199注释掉了(自发布此问题以来它没有更新,所以可能就是这样吗?)