2012-09-19 4 views
1

가능한 중복 : 나는 업로드하고 내 안드로이드 응용 프로그램에서 Google 드라이브에서 파일을 다운로드하려고 시도하고 있습니다
Android Open and Save files to/from Google Drive SDKAndroid 드라이브 개체를 초기화하여 Google 드라이브에 요청을 보내는 방법은 무엇인가요?

.

AccountManager.getAuthToken()을 사용하여 사용자의 Google 계정에 대한 인증 토큰 문자열을 얻을 수있었습니다.

이제 Google 드라이브에 요청을 보내기 위해 드라이브 토큰을 초기화하는 데 토큰을 사용하는 방법을 모르겠습니다. Google 드라이브의 부족한 문서에서 다음 코드를 사용했지만 제대로 작동하지 않습니다. 분명히 호출은 성공하지만 파일을 업로드하려고하면 Android가 앱이 응답하지 않는다고 알릴 때까지 전화가 끊깁니다.

GoogleCredential credential = new GoogleCredential().setAccessToken(authToken); 
HttpTransport httpTransport = new NetHttpTransport(); 
JsonFactory jsonFactory = new JacksonFactory(); 
Drive drive = null; 

drive = Drive.builder(httpTransport, jsonFactory) 
    .setApplicationName(APP_NAME) 
    .setHttpRequestInitializer(credential) 
    .setJsonHttpRequestInitializer(new GoogleKeyInitializer(API_KEY)) 
    .build(); 

내가 다음을 수행 특정 파일을 업로드하려면 : 나는 구글 API 문서를 읽은

try 
{ 
    // local file 
    java.io.File fileLocal = new java.io.File(FILE_NAME); 

    // remote file 

    File remoteFile = new File(); 
    remoteFile.setTitle(fileLocal.getName()); 
    remoteFile.setDescription("Text File"); 
    remoteFile.setMimeType("text/plain"); 

    // load the content of the local file into the remote content 
    FileContent remoteFileContent = new FileContent("text/plain", fileLocal); 

    // upload the file into Google Drive 
    File resultFile = drive.files().insert(remoteFile, remoteFileContent).execute(); 

    lblStatus.setText("Upload successful with file ID: " + resultFile.getId()); 
} 
catch (Exception e) 
{ 
    // error handling 
    ... 
} 

을하고 엉망이고, 클래스는 적절한 문서가 없습니다. 그들이주는 샘플은 상당히 엉망입니다.

앱이 응답하지 않는 이유는 무엇입니까? 내가 도대체 ​​뭘 잘못하고있는 겁니까? 어떤 도움을 주셔서 감사합니다. 감사.

답변

0

몇 주 전에이 문제가 발생했습니다. 여기서 Google 드라이브가 대부분 Android에서 작동하도록하는 방법에 대한 광범위한 설명을 작성했습니다. (대부분 파일 다운로드가 제대로 승인되지 않은 것 같아서 ...)

Android Open and Save files to/from Google Drive SDK

관련 문제