dropbox
HISTORY
# Dropbox, Inc., was founded in 2007 by MIT graduates Drew Houston and Arash Ferdowsi, as a Y Combinator startup company.
# Dropbox provides client software for Microsoft Windows, Mac OS X, Linux, Android, iOS, BlackBerry OS and web browsers, as well as unofficial ports to Symbian, Windows Phone and MeeGo.
WHAT IS DROPBOX ?
# Dropbox is a free service that lets you bring all your photos, docs, and videos anywhere.
# Dropbox also makes it super easy to share with others.
# Be Anywhere.
Conti.....
# Simple Sharing.
# Always safe.
# Change the files on the go.
Dropbox api's
# Core API.
# Sync API.
# Dropbox chooser
CORE API
# The Core API allows you to build the power of Dropbox directly into your app.
# It is not only make your app more powerful and easy to use.
Getting started with the Core API
# App folder (recomended)
# Full Dropbox
# Development Status
# Production Status
Set up the android sdk
# Starting up the example app
# App keys
# Adding the Dropbox SDK to an existing project
Conti...
<activity
android:name="com.dropbox.client2.android.AuthActivity"
android:launchMode="singleTask"
android:configChanges="orientation|keyboard">
<intent-filter>
<!-- Change this to be db- followed by your app key -->
<data android:scheme="db-INSERT-APP-KEY-HERE" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
setting up the libraries
# Right click on your project from the Package Explorer and go to Properties.
# Select Java Build Path from the sidebar.
# Add External JARs and add the libraries.
Adding authentication to your app
final static private String APP_KEY = "INSERT_APP_KEY_HERE";
final static private String APP_SECRET = "INSERT_SECRET_HERE";
final static private AccessType ACCESS_TYPE = AccessType.INSERT_APP_ACCESS_TYPE_HERE;
Create a Dropbox session
// In the class declaration section:
private DropboxAPI<AndroidAuthSession> mDBApi;
// And later in some initialization function:
AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);
Start the authentication process
if (mDBApi.getSession().authenticationSuccessful()) {
try {
// MANDATORY call to complete auth.
// Sets the access token on the session
mDBApi.getSession().finishAuthentication();
AccessTokenPair tokens = mDBApi.getSession().getAccessTokenPair();
// Provide your own storeKeys to persist the access token pair
// A typical way to store tokens is using SharedPreferences
storeKeys(tokens.key, tokens.secret);
} catch (IllegalStateException e) {
Log.i("DbAuthLog", "Error authenticating", e);
}
common api functions
# Upload file
Entry newEntry = mDBApi.putFile("/testing.txt", inputStream,
file.length(), null, null);
# Download file
DropboxFileInfo info = mDBApi.getFile("/testing.txt", null, outputStream, null);
Log.i("DbExampleLog", "The file's rev is: " + info.getMetadata().rev);
# Metadata
Sync api
# Dropbox built in
# write locally sync globally
# work offline
Getting started with the Sync API
# Adding the Sync API libraries to your project
# Configuring the Sync API
<service
android:name="com.dropbox.sync.android.DbxSyncService"
android:enabled="true"
android:exported="false"
android:label="Dropbox Sync" />
conti....
private DbxAccountManager mDbxAcctMgr;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDbxAcctMgr = DbxAccountManager.getInstance(getApplicationContext(),
APP_KEY, APP_SECRET);
}
Authenticating to Dropbox
static final int REQUEST_LINK_TO_DBX = 0; // This value is up to you
private void onClickLinkToDropbox() {
mDbxAcctMgr.startLink(this, REQUEST_LINK_TO_DBX);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_LINK_TO_DBX) {
if (resultCode == Activity.RESULT_OK) {
// ... Start using Dropbox files.
} else {
// ... Link failed or was cancelled by the user.
Listing Folders
List<DbxFileInfo> infos = dbxFs.listFolder(DbxPath.ROOT);
for (DbxFileInfo info : infos) {
Log.d("Dropbox Test", info.path + ", " + info.lastModified);
}
Working With files
DbxFile testFile = dbxFs.create(new DbxPath("hello.txt"));
try {
testFile.writeString("Hello Dropbox!");
} finally {
testFile.close();
}
Monitoring status with listeners
if (!testFile.getSyncStatus().isCached) {
testFile.addListener(this);
updateDownloadStatus(testFile); // Initial call ensures nothing is missed.
}
dbxFs.addPathListener(this, new DbxPath("/Notes"),
DbxFileSystem.PathListener.Mode.PATH_OR_CHILD);
dbxFs.addSyncStatusListener(this);
Thank you.
dropbox
By Torry Harris Business Solutions
dropbox
- 1,597