Reputation: 21
I'm having an issue setting up the dropbox-sdk for Android. When starting to execute the code I get the following "Unfortunately xxx has stopped"
.
At first I thought the issue may be in the manifest file as that's usually when I get the error for not correctly setting permissions. However, it says on the site the only permission required for authentication is the internet. I'll put the manifest file below.
The error is thrown when I call either AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET)
or AccessType ACCESS_TYPE = AccessType.APP_FOLDER
and for the life of me I can't figure out why. Declaring (but not initializing) DropboxAPI<AndroidAuthSession> mDBApi
is fine, which suggests that the libraries are being imported correctly.
I've changed them below so you all have to take my word on it but the key/secret constants are also correct so I doubt that it's that. Here's a snippet of my main activity:
package com.example.xxx.app;
import com.dropbox.client2.DropboxAPI;
import com.dropbox.client2.android.AndroidAuthSession;
import com.dropbox.client2.session.AppKeyPair;
import com.dropbox.client2.session.Session.AccessType;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
final static private String APP_KEY = "1234key";
final static private String APP_SECRET = "1234secret";
DropboxAPI<AndroidAuthSession> mDBApi;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AccessType ACCESS_TYPE = AccessType.APP_FOLDER;
AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);
setContentView(R.layout.activity_main);
}
And my manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xxx.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Dropbox Manifest -->
<activity
android:name="com.dropbox.client2.android.AuthActivity"
android:launchMode="singleTask"
android:configChanges="orientation|keyboard">
<intent-filter>
<data android:scheme="db-012345mykey" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Upvotes: 2
Views: 2840
Reputation: 89
Go to this site and create on app first. Dropbox will be provide you two keys : APP_KEY and APP_SECRET. The resultant value of these key put in your app. If you find any issue then please let me know.
For detail please visit here.
Upvotes: 1
Reputation: 125
Where is your onResume()?
protected void onResume() {
super.onResume();
// ...
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);
}
}
// ...
}
https://www.dropbox.com/developers/start/authentication#android
Upvotes: 0