2012-08-13 49 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()); 
     }  
    }