Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7936373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:11:41+00:00 2026-06-03T22:11:41+00:00

I want to sync the local database file in the Android app with the

  • 0

I want to sync the local database file in the Android app with the users’ DropBox or SkyDrive account. Anything would do.
I am not able to get a running code.
Please help.

Here is the code I got from the official DropBox site, but it says error at
“final static private AccessType ACCESS_TYPE = AccessType.APP_FOLDER;” as NoClassDefFoundError

public class DBRoulette extends Activity {
private static final String TAG = "DBRoulette";

///////////////////////////////////////////////////////////////////////////
//                      Your app-specific settings.                      //
///////////////////////////////////////////////////////////////////////////

// Replace this with your app key and secret assigned by Dropbox.
// Note that this is a really insecure way to do this, and you shouldn't
// ship code which contains your key & secret in such an obvious way.
// Obfuscation is good.
final static private String APP_KEY = "5gqlcpeirbe9kju";
final static private String APP_SECRET = "zs9bi3nwqf4arn2";

// If you'd like to change the access type to the full Dropbox instead of
// an app folder, change this value.
final static private AccessType ACCESS_TYPE = AccessType.APP_FOLDER;

///////////////////////////////////////////////////////////////////////////
//                      End app-specific settings.                       //
///////////////////////////////////////////////////////////////////////////

// You don't need to change these, leave them alone.
final static private String ACCOUNT_PREFS_NAME = "prefs";
final static private String ACCESS_KEY_NAME = "ACCESS_KEY";
final static private String ACCESS_SECRET_NAME = "ACCESS_SECRET";


DropboxAPI<AndroidAuthSession> mApi;

private boolean mLoggedIn;

// Android widgets
private Button mSubmit;
private LinearLayout mDisplay;
private Button mPhoto;
private Button mRoulette;

private ImageView mImage;

private final String PHOTO_DIR = "/Photos/";

final static private int NEW_PICTURE = 1;
private String mCameraFileName;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        mCameraFileName = savedInstanceState.getString("mCameraFileName");
    }

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

    // Basic Android widgets
    setContentView(R.layout.main);

    checkAppKeySetup();

    mSubmit = (Button)findViewById(R.id.auth_button);

    mSubmit.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // This logs you out if you're logged in, or vice versa
            if (mLoggedIn) {
                logOut();
            } else {
                // Start the remote authentication
                mApi.getSession().startAuthentication(DBRoulette.this);
            }
        }
    });

    mDisplay = (LinearLayout)findViewById(R.id.logged_in_display);

    // This is where a photo is displayed
    mImage = (ImageView)findViewById(R.id.image_view);

    // This is the button to take a photo
    mPhoto = (Button)findViewById(R.id.photo_button);

    mPhoto.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            // Picture from camera
            intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);

            // This is not the right way to do this, but for some reason, having
            // it store it in
            // MediaStore.Images.Media.EXTERNAL_CONTENT_URI isn't working right.

            Date date = new Date();
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd-kk-mm-ss");

            String newPicFile = df.format(date) + ".jpg";
            String outPath = "/sdcard/" + newPicFile;
            File outFile = new File(outPath);

            mCameraFileName = outFile.toString();
            Uri outuri = Uri.fromFile(outFile);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, outuri);
            Log.i(TAG, "Importing New Picture: " + mCameraFileName);
            try {
                startActivityForResult(intent, NEW_PICTURE);
            } catch (ActivityNotFoundException e) {
                showToast("There doesn't seem to be a camera.");
            }
        }
    });


    // This is the button to take a photo
    mRoulette = (Button)findViewById(R.id.roulette_button);

    mRoulette.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            DownloadRandomPicture download = new DownloadRandomPicture(DBRoulette.this, mApi, PHOTO_DIR, mImage);
            download.execute();
        }
    });

    // Display the proper UI state if logged in or not
    setLoggedIn(mApi.getSession().isLinked());

}

@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putString("mCameraFileName", mCameraFileName);
    super.onSaveInstanceState(outState);
}

@Override
protected void onResume() {
    super.onResume();
    AndroidAuthSession session = mApi.getSession();

    // The next part must be inserted in the onResume() method of the
    // activity from which session.startAuthentication() was called, so
    // that Dropbox authentication completes properly.
    if (session.authenticationSuccessful()) {
        try {
            // Mandatory call to complete the auth
            session.finishAuthentication();

            // Store it locally in our app for later use
            TokenPair tokens = session.getAccessTokenPair();
            storeKeys(tokens.key, tokens.secret);
            setLoggedIn(true);
        } catch (IllegalStateException e) {
            showToast("Couldn't authenticate with Dropbox:" + e.getLocalizedMessage());
            Log.i(TAG, "Error authenticating", e);
        }
    }
}

// This is what gets called on finishing a media piece to import
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == NEW_PICTURE) {
        // return from file upload
        if (resultCode == Activity.RESULT_OK) {
            Uri uri = null;
            if (data != null) {
                uri = data.getData();
            }
            if (uri == null && mCameraFileName != null) {
                uri = Uri.fromFile(new File(mCameraFileName));
            }
            File file = new File(mCameraFileName);

            if (uri != null) {
                UploadPicture upload = new UploadPicture(this, mApi, PHOTO_DIR, file);
                upload.execute();
            }
        } else {
            Log.w(TAG, "Unknown Activity Result from mediaImport: "
                    + resultCode);
        }
    }
}

private void logOut() {
    // Remove credentials from the session
    mApi.getSession().unlink();

    // Clear our stored keys
    clearKeys();
    // Change UI state to display logged out version
    setLoggedIn(false);
}

/**
 * Convenience function to change UI state based on being logged in
 */
private void setLoggedIn(boolean loggedIn) {
    mLoggedIn = loggedIn;
    if (loggedIn) {
        mSubmit.setText("Unlink from Dropbox");
        mDisplay.setVisibility(View.VISIBLE);
    } else {
        mSubmit.setText("Link with Dropbox");
        mDisplay.setVisibility(View.GONE);
        mImage.setImageDrawable(null);
    }
}

private void checkAppKeySetup() {
    // Check to make sure that we have a valid app key
    if (APP_KEY.startsWith("CHANGE") ||
            APP_SECRET.startsWith("CHANGE")) {
        showToast("You must apply for an app key and secret from developers.dropbox.com, and add them to the DBRoulette ap before trying it.");
        finish();
        return;
    }

    // Check if the app has set up its manifest properly.
    Intent testIntent = new Intent(Intent.ACTION_VIEW);
    String scheme = "db-" + APP_KEY;
    String uri = scheme + "://" + AuthActivity.AUTH_VERSION + "/test";
    testIntent.setData(Uri.parse(uri));
    PackageManager pm = getPackageManager();
    if (0 == pm.queryIntentActivities(testIntent, 0).size()) {
        showToast("URL scheme in your app's " +
                "manifest is not set up correctly. You should have a " +
                "com.dropbox.client2.android.AuthActivity with the " +
                "scheme: " + scheme);
        finish();
    }
}

private void showToast(String msg) {
    Toast error = Toast.makeText(this, msg, Toast.LENGTH_LONG);
    error.show();
}

/**
 * Shows keeping the access keys returned from Trusted Authenticator in a local
 * store, rather than storing user name & password, and re-authenticating each
 * time (which is not to be done, ever).
 *
 * @return Array of [access_key, access_secret], or null if none stored
 */
private String[] getKeys() {
    SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
    String key = prefs.getString(ACCESS_KEY_NAME, null);
    String secret = prefs.getString(ACCESS_SECRET_NAME, null);
    if (key != null && secret != null) {
        String[] ret = new String[2];
        ret[0] = key;
        ret[1] = secret;
        return ret;
    } else {
        return null;
    }
}

/**
 * Shows keeping the access keys returned from Trusted Authenticator in a local
 * store, rather than storing user name & password, and re-authenticating each
 * time (which is not to be done, ever).
 */
private void storeKeys(String key, String secret) {
    // Save the access key for later
    SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
    Editor edit = prefs.edit();
    edit.putString(ACCESS_KEY_NAME, key);
    edit.putString(ACCESS_SECRET_NAME, secret);
    edit.commit();
}

private void clearKeys() {
    SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
    Editor edit = prefs.edit();
    edit.clear();
    edit.commit();
}

private AndroidAuthSession buildSession() {
    AppKeyPair appKeyPair = new AppKeyPair(APP_KEY, APP_SECRET);
    AndroidAuthSession session;

    String[] stored = getKeys();
    if (stored != null) {
        AccessTokenPair accessToken = new AccessTokenPair(stored[0], stored[1]);
        session = new AndroidAuthSession(appKeyPair, ACCESS_TYPE, accessToken);
    } else {
        session = new AndroidAuthSession(appKeyPair, ACCESS_TYPE);
    }

    return session;
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:11:44+00:00Added an answer on June 3, 2026 at 10:11 pm

    Do you add the dropbox-android-sdk.jar in your buildPath and in a correct way ?

    The DropboxAPI JAR file should be in the libs/ folder, not lib/.

    Try this and tell me if it works now …

    PS: I’m working with DropboxAPI for android, and their code works very well for me and their documentation is really good to do your own application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on my fist app for android phones and I want to
I'm developing an app which will have a central database users can add entries
I would like to create post-commit hook in tortoiseSVN. I want to copy (sync)
I'm building an client/server-app where I want to sync data. I'm thinking about including
I have an SQLite database for my Android app that stores a copy of
I need to make a shared folder in android. I want to be able
I want to add a new calendar to Android that does not get synchronized.
I want sync data from iphone to the webs server. My question is how
I have a web application that I want to sync with Flickr. I don't
Want to be able to provide a search interface for a collection of objects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.