0

I have written this code in Android Studio but as soon as I launch the app it crashes.

package PACKAGE_NAME;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

import com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.v2.DbxClientV2;

public class MainActivity extends AppCompatActivity {

    private static final String ACCESS_TOKEN = MY_ACCESS_TOKEN;
    DbxRequestConfig config = DbxRequestConfig.newBuilder("db").build();
    DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        try {
            ((TextView)findViewById(R.id.textView)).setText(client.users().getCurrentAccount().getName().getDisplayName());
        } catch (DbxException e) {
            e.printStackTrace();
        }
    }
}

I would like to connect to my Dropbox account via access token, I did a similar thing in python and it actually worked. Someone who knows why this happens?

  • What error do you get in the log? Based on this code I expect you're getting a `NetworkOnMainThreadException` for instance: https://stackoverflow.com/questions/6343166/how-to-fix-android-os-networkonmainthreadexception – Greg Oct 01 '20 at 17:09
  • Yes, do you know how I should create the new class(the async one)? – Francesco Oct 01 '20 at 17:34
  • In addition to the StackOverflow question I linked to, check out [the Android example included with the Dropbox Java SDK](https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/android). – Greg Oct 01 '20 at 18:10

0 Answers0