检查dir是否存在且dir包含在dropbox api上不起作用

时间:2012-08-13 09:12:51

标签: java android dropbox dropbox-api

DBRoulette.java

private final String DATA_DIR = "/DataBase/";   

收存箱

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 有谁知道如何解决它?

2 个答案:

答案 0 :(得分: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 :(得分: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() );
        }       
    }