当前位置: 首页>>代码示例>>Java>>正文


Java DropboxAPI类代码示例

本文整理汇总了Java中com.dropbox.client2.DropboxAPI的典型用法代码示例。如果您正苦于以下问题:Java DropboxAPI类的具体用法?Java DropboxAPI怎么用?Java DropboxAPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DropboxAPI类属于com.dropbox.client2包,在下文中一共展示了DropboxAPI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isLinked

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public boolean isLinked(Activity activity) {
		try {

		AppKeyPair appKeys = new AppKeyPair(StaticConfig.dropboxAppKey, StaticConfig.dropboxAppSecret);
		AndroidAuthSession session = new AndroidAuthSession(appKeys, AccessType.DROPBOX);
		api = new DropboxAPI<AndroidAuthSession>(session);		
//		
		KeyValueBean loginPwd = getLoginPwd(activity);
		AccessTokenPair atp = new AccessTokenPair(loginPwd.getKey(),loginPwd.getValue());
		api.getSession().setAccessTokenPair(atp);
//		return api.getSession().isLinked();
		api.metadata("/", 1, null, false, null);
		return true;
		}
		catch (DropboxException e){
			return false;
		}
		

	}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:21,代码来源:FileProvider4.java

示例2: initialize

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
private void initialize(String token) {
    LogUtil.log(getClass().getSimpleName(), "initialize()");

    AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
    AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);

    mDBApi = new DropboxAPI<>(session);

    if ( token == null )
        token = Settings.getDropboxSyncToken();

    if ( token != null )
        mDBApi.getSession().setOAuth2AccessToken(token);

    if (!doesFolderExist(getBaseFilePath())) {
        try {
            createFileStructure();
        } catch (DropboxException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:timothymiko,项目名称:narrate-android,代码行数:23,代码来源:DropboxSyncService.java

示例3: listFiles

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public List<String> listFiles() throws Exception {
    if (authSession()) {
        try {
            List<String> files = new ArrayList<>();
            List<DropboxAPI.Entry> entries = dropboxApi.search("/", ".backup", 1000, false);
            for (DropboxAPI.Entry entry : entries) {
                if (entry.fileName() != null) {
                    files.add(entry.fileName());
                }
            }
            Collections.sort(files, new Comparator<String>() {
                @Override
                public int compare(String s1, String s2) {
                    return s2.compareTo(s1);
                }
            });
            return files;
        } catch (Exception e) {
            Log.e("Flowzr", "Dropbox: Something wrong", e);
            throw new ImportExportException(R.string.dropbox_error, e);
        }
    } else {
        throw new ImportExportException(R.string.dropbox_auth_error);
    }
}
 
开发者ID:emmanuel-florent,项目名称:flowzr-android-black,代码行数:26,代码来源:Dropbox.java

示例4: Login

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
/**
 * Have the user login to their dropbox account.
 * If the access tokens are saved from a previous
 * login, they will be used, otherwise the user
 * will have to login again.
 * 
 */
public void Login() {
	if (access_type != null) {			
 		if (!loggedIn) {
 			AndroidAuthSession session = buildSession();
 			dbApi = new DropboxAPI<AndroidAuthSession>(session);
 			if (container==null) {
 				dbApi.getSession().startAuthentication(sContainer.$formService());
 			} else {
 				dbApi.getSession().startAuthentication(container.$form());
 			}
 		}
	} else {
		Log.e(TAG, "AccessType is null! You MUST provide an AccessType to connect and login.");
	}
}
 
开发者ID:roadlabs,项目名称:alternate-java-bridge-library,代码行数:23,代码来源:DropBoxClient.java

示例5: connect

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
/**
 * Handles the authentication process.
 * The generated accessToken is saved, so that the user does not have to enter his/her credentials every time.
 */
@Override
public void connect() {
	// Start new authentication
	AndroidAuthSession mSession = new AndroidAuthSession(mAppKeys);
	
	// The DropboxAPI Instance
	mDBApi = new DropboxAPI<AndroidAuthSession>(mSession);
	
	this.accessToken = settings.getDropboxAuthToken();
	
	// When access token already exists in properties use it instead of starting new authentication
	if (accessToken.isEmpty()) {
		mDBApi.getSession().startOAuth2Authentication(activity);
	} else {
		mDBApi.getSession().setOAuth2AccessToken(accessToken);
	}
}
 
开发者ID:Rohde-Schwarz-Cybersecurity,项目名称:PanBox,代码行数:22,代码来源:DropboxConnector.java

示例6: disconnect

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
/**
 * Unlinks the app from the users dropbox.
 */
@Override
public void disconnect() {
	// Check first if application DB API link is still up!
	if(mDBApi == null) {
		// Start new authentication
		AndroidAuthSession mSession = new AndroidAuthSession(mAppKeys);
		
		// The DropboxAPI Instance
		mDBApi = new DropboxAPI<AndroidAuthSession>(mSession);
	}
	mDBApi.getSession().unlink();
	settings.setDropboxAuthToken("");
	settings.writeChanges();
	accessToken = "";
}
 
开发者ID:Rohde-Schwarz-Cybersecurity,项目名称:PanBox,代码行数:19,代码来源:DropboxConnector.java

示例7: uploadFile

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
/**
 * A helper method that uploads a file whose path is passed as parameter to Dropbox.
 *
 * @param path Path to the file that should be uploaded to Dropbox.
 * @throws FileNotFoundException If {@code file} does not exist.
 * @throws DropboxException      If a Dropbox related exception occurs.
 */
private void uploadFile(String path) throws FileNotFoundException, DropboxException {
    File file = new File(path);
    FileInputStream inputStream = null;
    try {
        inputStream = new FileInputStream(file);
        DropboxAPI.Entry response = dropboxApi.putFile('/' + file.getName(), inputStream, file.length(), null, null);
        Log.i(TAG, "uploadFile() :: The uploaded file's rev is: " + response.rev);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:dbaldwin,项目名称:DroidMapper,代码行数:25,代码来源:DropboxUploaderThread.java

示例8: testRemoteFileMissing

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public void testRemoteFileMissing() {
    DropboxAPI<?> dropboxapi = new DropboxAPIStub() {
        public DropboxAPI.Entry metadata(String arg0, int arg1,
                String arg2, boolean arg3, String arg4)
                throws DropboxException {
            throw notFoundException();
        }
    };

    DropboxFileDownloader downloader = new DropboxFileDownloader(
            dropboxapi, dropboxFiles1);

    downloader.pullFiles();
    assertEquals("Status should be SUCCESS", DropboxFileStatus.SUCCESS,
            downloader.getStatus());
    assertEquals("Should have 1 file", 1, downloader.getFiles().size());
    assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND,
            dbFile1.getStatus());
}
 
开发者ID:GoogleCloudPlatform,项目名称:endpoints-codelab-android,代码行数:20,代码来源:DropboxFileDownloaderTest.java

示例9: testRemoteFileDeleted

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public void testRemoteFileDeleted() {
    DropboxAPI<?> dropboxapi = new DropboxAPIStub() {
        public DropboxAPI.Entry metadata(String arg0, int arg1,
                String arg2, boolean arg3, String arg4)
                throws DropboxException {
            return create_metadata(remoterev1, true);
        }
    };

    DropboxFileDownloader downloader = new DropboxFileDownloader(
            dropboxapi, dropboxFiles1);

    downloader.pullFiles();
    assertEquals("Status should be SUCCESS", DropboxFileStatus.SUCCESS,
            downloader.getStatus());
    assertEquals("Should have 1 file", 1, downloader.getFiles().size());
    assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND,
            dbFile1.getStatus());
}
 
开发者ID:GoogleCloudPlatform,项目名称:endpoints-codelab-android,代码行数:20,代码来源:DropboxFileDownloaderTest.java

示例10: testBothFilesMissing

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public void testBothFilesMissing() {
    DropboxAPI<?> dropboxapi = new DropboxAPIStub() {
        public DropboxAPI.Entry metadata(String arg0, int arg1,
                String arg2, boolean arg3, String arg4)
                throws DropboxException {
            throw notFoundException();
        }
    };

    DropboxFileDownloader downloader = new DropboxFileDownloader(
            dropboxapi, dropboxFiles2);

    downloader.pullFiles();
    assertEquals("Status should be SUCCESS", DropboxFileStatus.SUCCESS,
            downloader.getStatus());
    assertEquals("Should have 2 files", 2, downloader.getFiles().size());
    assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND,
            dbFile1.getStatus());
    assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND,
            dbFile2.getStatus());
}
 
开发者ID:GoogleCloudPlatform,项目名称:endpoints-codelab-android,代码行数:22,代码来源:DropboxFileDownloaderTest.java

示例11: UploadFile

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public UploadFile(Context context, DropboxAPI<?> api, String dropboxPath,
        File file) {
    // We set the context this way so we don't accidentally leak activities
    mContext = context.getApplicationContext();

    mFileLen = file.length();
    mApi = api;
    mPath = dropboxPath;
    mFile = file;

    mDialog = new ProgressDialog(context);
    mDialog.setMax(100);
    mDialog.setMessage("Uploading " + file.getName());
    mDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    mDialog.setProgress(0);
    mDialog.setButton("Cancel", new OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // This will cancel the putFile operation
            mRequest.abort();
        }
    });
    mDialog.show();
}
 
开发者ID:mobilars,项目名称:BLEConnect,代码行数:24,代码来源:UploadFile.java

示例12: createPhotoFolder

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
/**
 * Creates a directory for photos if one does not already exist. If the folder already exists, this call will
 * do nothing.
 *
 * @param dropboxApi the {@link DropboxAPI}.
 * @return true if the directory is created or it already exists; false otherwise.
 */
private boolean createPhotoFolder(DropboxAPI<AndroidAuthSession> dropboxApi) {
    boolean folderCreated = false;
    if (dropboxApi != null) {
        try {
            dropboxApi.createFolder(mContext.getString(R.string.wings_dropbox__photo_folder));
            folderCreated = true;
        } catch (DropboxException e) {
            // Consider the folder created if the folder already exists.
            if (e instanceof DropboxServerException) {
                folderCreated = DropboxServerException._403_FORBIDDEN == ((DropboxServerException) e).error;
            }
        }
    }
    return folderCreated;
}
 
开发者ID:groundupworks,项目名称:wings,代码行数:23,代码来源:DropboxEndpoint.java

示例13: getFilesInDir

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public Set<String> getFilesInDir(String dirName, String query)
{
    Set<String> retVal = null;

    if( isConnected() ) {
        try {
            Log.d(TAG, "Getting files in: " + dirName);

            DropboxAPI.Entry entries = mDBApi.metadata("/" + dirName, MAX_DROPBOX_FILES, null, true, null);

            // Move list of files into hashset
            retVal = new HashSet<String>();
            for( DropboxAPI.Entry entry : entries.contents )
            {
                retVal.add( entry.fileName() );
            }
        } catch( DropboxException e )
        {
            e.printStackTrace();
        }
    }
    return retVal;
}
 
开发者ID:bright-tools,项目名称:androidphotobackup,代码行数:24,代码来源:DropBoxWrapper.java

示例14: fileExists

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public boolean fileExists(String fileName)
{
    boolean retVal = false;
    if( isConnected() ) {
        try {
            DropboxAPI.Entry existingEntry = mDBApi.metadata("/" + fileName, 1, null, false, null);
            if ((!existingEntry.isDir) && (!existingEntry.isDeleted)) {
                retVal = true;
            }
        } catch( DropboxException e )
        {
            e.printStackTrace();
        }
    }
    return retVal;
}
 
开发者ID:bright-tools,项目名称:androidphotobackup,代码行数:17,代码来源:DropBoxWrapper.java

示例15: onCreate

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  Log.d("michael", "Dropboxclient.onCreate");

  // We create a new AuthSession so that we can use the Dropbox API.
  AndroidAuthSession session = buildSession();
  mApi = new DropboxAPI<AndroidAuthSession>(session);

  checkAppKeySetup();

  if (session.getAccessTokenPair() != null) {
    setLoggedIn(true);
    init();
  } else {
    // Start the remote authentication
    mApi.getSession().startAuthentication(DropboxClient.this);
    // Get the metadata for a directory
    setLoggedIn(mApi.getSession().isLinked());
  }
}
 
开发者ID:LiteracyBridge,项目名称:software,代码行数:23,代码来源:DropboxClient.java


注:本文中的com.dropbox.client2.DropboxAPI类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。