2017-11-02 1 views
0
@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.Type.FILE이 호출되지 않고 Payload.Type.BYTES 만 호출됩니다. https://developers.google.com/nearby/connections/android/exchange-data에서onPayloadReceived 인근 연결 2.0은 파일 페이로드를 수신하지 않습니다.

조각 sendPayload()

// 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 파일 페이로드를 전송하는 코드가에 주석처럼 보이는

답변

0

에게있어210 (이 질문을 게시 한 이래로 업데이트되지 않았습니다.)

+0

코드 # L199에서 # L473이 (가) 이전에 제안 된대로 옮겨졌으며 스레드 수면 (내가 생각할 수있는 가장 간단한 방법)이 추가되었습니다. 수신자가 준비 될 때까지 100 % 확신하지만 결과는 아직 없음 – toasty

관련 문제