0

I am trying to upload a file to dropbox. I have configured manifest file, and written the below code. Please help me understand what I am missing here. Activity onClick

Intent uploadToDropbox = new Intent(this, SUploadDB2Dropbox.class); 
            startService(uploadToDropbox) ;

Service SUploadDB2Dropbox

private DropboxAPI<AndroidAuthSession> mDBApi;

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        AppKeyPair appKeys = new AppKeyPair(God.DROPBOX_APP_KEY,
                God.DROPBOX_APP_SECRET);
        AndroidAuthSession session = new AndroidAuthSession(appKeys);
        mDBApi = new DropboxAPI<AndroidAuthSession>(session);
        mDBApi.getSession().startOAuth2Authentication(this);
        UploadDB2DropBox upload2DropBox = new UploadDB2DropBox(this, mDBApi);
        upload2DropBox.execute();
        return super.onStartCommand(intent, flags, startId);
    }

UploadDB2DropBox AsyncTask

@Override
    public String doInBackground(Object... params) {
        File file = new File(context.getDatabasePath(God.TABLE_ACTIVATIONS)
                + ".db");
        Log.d(God.TAG,
                "Database path "
                        + context.getDatabasePath(God.TABLE_ACTIVATIONS));

        FileInputStream inputStream = null;
        try {
            String newFileName;
            inputStream = new FileInputStream(file);

            newFileName = "/" + God.TABLE_ACTIVATIONS
                    + Calendar.getInstance().getTimeInMillis() + ".db";
            Log.d(God.TAG, "File path " + file.getName() + " len "
                    + inputStream.available());
            Log.d(God.TAG, " New Filename " + newFileName);
            Entry response = mDBApi.putFile(newFileName, inputStream,
                    file.length(), null, null);
            Log.d(God.TAG, "Uploaded file is " + response.rev);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            Log.e(God.TAG, "FileNotFoundException");
        } catch (DropboxException e) {
            e.printStackTrace();n
            Log.e(God.TAG, "DropboxException");
        } catch (IOException e) {
            Log.e(God.TAG, "IOException");
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    Log.e(God.TAG, "IOException");
                }
            }
        }
        return null;
    }

I am getting a dropbox exception. The screen does navigate to the dropbox Allow user screen (everytime though).

Logcat

02-23 11:44:19.435: D/AutoActivate(27289): Database path /data/data/com.swipex.autoactivate/databases/activations
02-23 11:44:19.436: D/AutoActivate(27289): File path activations.db len 8372224
02-23 11:44:19.546: D/AutoActivate(27289):  New Filename /activations1424672059436.db
02-23 11:44:19.702: E/AutoActivate(27289): DropboxException

Manifest File

<activity
            android:name="com.dropbox.client2.android.AuthActivity"
            android:configChanges="orientation|keyboard"
            android:launchMode="singleTask" >
            <intent-filter>
                <data android:scheme="db-KEY_VALUE_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>

I am getting a UnlinkException

DropboxUnlinkedException - if you have not set an access token pair on the session, or if the user has revoked access.

What am I missing ?

Siddharth
  • 9,349
  • 16
  • 86
  • 148
  • To clarify, your **>>EXCEPTION_HERE** marker is on a Log.e line. Is it actually occurring on that line, or on one of the lines above it? – Greg Feb 10 '15 at 23:10
  • Sorry, I'll make the correction, I see what you are saying. – Siddharth Feb 11 '15 at 04:39
  • You're pointing out the `putFile` line, but the stack trace doesn't seem to mention this, or even the `UploadDB2DropBox` class you posted. Are you sure this exception is coming from this code? It looks like there's another question about this error here: http://stackoverflow.com/questions/11308260/chooseractivity-has-leaked-intentreceiver – Greg Feb 11 '15 at 21:23
  • Yes, there are other questions on the unregister exception. I know how to fix them for send sms and send email's, but for dropbox there is a internal registration that happens for a intentservice. Ideally dropbox api should have unregistered. This question is unique for dropbox api's. The regular unregister fixes wont work for this issue. – Siddharth Feb 12 '15 at 04:09
  • Ok, can you clarify why the stack doesn't reference any of your posted code though? And in any case, if you've found a bug in the Dropbox Android Core SDK, please report it along with steps to reproduce it, or ideally a small sample project showing it, here: https://www.dropbox.com/developers/contact – Greg Feb 12 '15 at 21:00
  • Only after I added this code this exception started showing up. – Siddharth Feb 13 '15 at 15:10
  • [Cross-linking for reference: https://www.dropboxforum.com/hc/communities/public/questions/201866499-Dropbox-com-android-packageinstaller-InstallAppProgress-has-leaked-IntentReceiver ] – Greg Feb 18 '15 at 18:14
  • As of now, I have given up on dropbox api's. Considering that its badly documented, implemented and supported worse. – Siddharth Feb 20 '15 at 05:48
  • I have added the sample project, here now. I hope this is enough information. Please let me know if more information is needed. – Siddharth Feb 23 '15 at 06:19
  • You downvoted the question because I corrected it ? Strange behavior dude. Read the FAQ please. If this is the kind of support you get from dropbox developers, I am not surprised how easily a badly documented (and implemented) can you end up with.. Children.. – Siddharth Feb 24 '15 at 15:26

1 Answers1

0

Terrible dropbox documentation I must say

public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(God.TAG, "Initializing Dropbox");
        AppKeyPair appKeys = new AppKeyPair(God.DROPBOX_APP_KEY,
                God.DROPBOX_APP_SECRET);
        AndroidAuthSession session = new AndroidAuthSession(appKeys);
        mDBApi = new DropboxAPI<AndroidAuthSession>(session);
        mDBApi.getSession().startOAuth2Authentication(this);
        if (mDBApi != null && mDBApi.getSession().authenticationSuccessful()) {
            try {
                // Required to complete auth, sets the access token on the session
                mDBApi.getSession().finishAuthentication();
                UploadDB2DropBox upload2DropBox = new UploadDB2DropBox(this,
                        mDBApi);
                upload2DropBox.execute();

                //String accessToken = mDBApi.getSession().getOAuth2AccessToken();
            } catch (IllegalStateException e) {
                Log.i(God.TAG, "Error authenticating", e);
            }
        }
        return super.onStartCommand(intent, flags, startId);
    }

This helped. I wonder why dropbox keeps asking for permission from the UI. Its stupid to use this api if I have to keep asking for permission.

Siddharth
  • 9,349
  • 16
  • 86
  • 148