-1

저는 SD 카드의 특정 폴더에서 Google 드라이브로 이미지 파일을 업로드 할 Android 애플리케이션을 설계 중입니다. saveFileToDrive 드라이브를 Google에 하나 개의 파일을 업로드하는 로직을 포함SD 카드에서 Google 드라이브로 이미지를 여러 개 업로드하는 방법은 무엇인가요?

File sdDir = Environment 
       .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 
    File yourDir = new File(sdDir, "CameraAPIDemo"); 
    for (File f : yourDir.listFiles()) { 
     if (f.isFile()){ 
      String name = f.getName(); 
      Log.i(TAG, "name =" + name); 
      String CompletePath=yourDir + "/" + name; 
      //Decode the file from the folder to bitmap 
      Bitmap bmp = BitmapFactory.decodeFile(CompletePath); 
      saveFileToDrive(sFolderId,bmp,name); 

    } 

:하지만 난

E/AndroidRuntime(6808): FATAL EXCEPTION: main 
E/AndroidRuntime(6808): java.lang.OutOfMemoryError error while trying to upload the files. 

코드를 얻고있다. 진행 방법? 제발 도와주세요 .....

답변

0

saveFileToDrive가 UI에서 분리 된 스레드에서 실행 중이라고 가정 할 때 점진적으로 모든 이미지를 for 루프의 메모리에로드하는 중입니다. SD 디렉토리의 모든 파일을 메모리에로드하고 모두 스레드로 인해 병렬로 드라이브에 업로드하려고 시도하는 것으로 보입니다.

간단한 해결책은 saveFileToDrive를 @Override onPostExecute() 메서드 (UI 스레드에서)의 루프를 알리는 AsyncTask로 만드는 것입니다. UI가 지연되지 않도록 한 번에 하나씩 업로드하므로 별도의 스레드에서 사진을 업로드하면 이 부족해서는 안됩니다.

여기를 방문한 적이 있습니까? https://developers.google.com/drive/android/create-file?

관련 문제