2012-08-13 88 views
0

DBRoulette.java檢查目錄存在,目錄包含將無法在Dropbox的API工作

private final String DATA_DIR = "/DataBase/"; 

Dropbox的

DownloadRandomPicture

public DownloadRandomPicture(Context context, DropboxAPI<?> api, 
      String dropboxPath, ImageView view) { 
    mPath = dropboxPath; 

doInBackground()

Entry dirent = mApi.metadata(mPath, 1000, null, true, null); 
if (!dirent.isDir || dirent.contents == null) { 
        // It's not a directory, or there's nothing in it 
        mErrorMsg = "File or empty directory"; 
        return false; 
       } 

此代碼不能在DownloadRandomPicture.java 任何人知道如何解決它?

+1

是什麼'dirent'的類型? – 2012-08-13 09:15:48

+0

@Jigar Joshi編輯,對不起 – Sieryuu 2012-08-13 09:21:08

回答

1

如果我們使用

final static private AccessType ACCESS_TYPE = AccessType.DROPBOX; 

我們應該

Entry dirent = mApi.metadata(mPath, 1000, null, false, null); 

,但是如果我們使用

final static private AccessType ACCESS_TYPE = AccessType.APP_FOLDER; 

我們應該用

Entry dirent = mApi.metadata(mPath, 1000, null, true, null);  

所不同的是在在的dirent

1

布爾試試這個,它的對您有用...

try 
    { 
     Entry existingEntry = mApi.metadata("/" + SavedProperties.selectedAddress , 1, null, false, null); 
     if(existingEntry.isDir) 
     { 
      Log.d(TAG, "Folder exists : " + existingEntry.fileName()); 
      uploadPictures("/"+SavedProperties.selectedAddress + "/"); 
     } 
    } 
    catch (DropboxException e) 
    { 
     Log.d(TAG,"Folder does not exist..." + e.fillInStackTrace()); 
     try 
     { 
      Entry createFolder = mApi.createFolder("/"+SavedProperties.selectedAddress); 
      Log.d(TAG,"Folder created..." + createFolder.rev); 
      uploadPictures("/"+SavedProperties.selectedAddress + "/"); 
     } 
     catch (DropboxException e1) 
     { 
      Log.d(TAG,"Create Folder DropboxException : " + e1.fillInStackTrace()); 
     }  
    }