dnsiv
dnsiv

Reputation: 520

Connecting to Google Spreadsheet

I am trying to connect to google Spreadsheet via java according to https://developers.google.com/sheets/api/quickstart/java .

If I am executing this sample on my IDE, it's working without problems. Now I want to integrate this sample into my android app. The first activity directly calls the main-method of the previous link (code is in step3 of link. The main method has been renamed, in order to be called by the activity). But I am getting an Error:

    W/System.err: java.io.IOException: unable to create directory: /tokens
    W/System.err:     at com.google.api.client.util.store.FileDataStoreFactory.<init>(FileDataStoreFactory.java:61)
    W/System.err:     at com.kazumi.management.ConnectToDatabase.getCredentials(ConnectToDatabase.java:70)

According to the error, it should be this line:

GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
                .setAccessType("offline")
                .build();

So the reason is, that this function isn't able to create a directory on my virtual android device. But why is it like that? And does there exist a workaround?

Upvotes: 0

Views: 241

Answers (1)

dnsiv
dnsiv

Reputation: 520

So I found the solution by myself. Internal and External Storage are difficult to access on android (https://developer.android.com/guide/topics/data/data-storage)

So in order to create a directory on my internal storage, I need to use this:

File folder = getDir("theFolder",Context.MODE_PRIVATE);

Upvotes: 1

Related Questions