PureSpider
PureSpider

Reputation: 407

Trying to use Google Tasks API on android keeps my app crashing

I'm trying to build a simple todo app for Android using the Google Tasks API.
However, whatever I try and change or include, my app compiles fine but crashes on the phone whenever I try to use the tasks API.
All the libraries are in my libs folder but I can't fand what dependencies I also need to include. This is my current code, once I remove the comments of the tasks lines my app crashes right after opening on the phone.
The jack thing is for testing the JacksonFactory is not the fault.
The problem might be that I am calling new GoogleAccessProtectedResource(null) which has to be called with an oAuth authkey?

package de.purespider.tasks;

import android.app.Activity;
import android.os.Bundle;

import com.google.api.client.extensions.android2.AndroidHttp;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource;
import com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.tasks.Tasks;
import com.google.api.services.tasks.model.Task;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

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

    // This must be the exact string, and is a special for alias OAuth 2 scope
    // "https://www.googleapis.com/auth/tasks"
    private static final String AUTH_TOKEN_TYPE = "Manage your tasks";

    private static final String PREF = "MyPrefs";
    private static final int DIALOG_ACCOUNTS = 0;
    private static final int MENU_ACCOUNTS = 0;
    public static final int REQUEST_AUTHENTICATE = 0;

    private final HttpTransport transport = AndroidHttp.newCompatibleTransport();

    Tasks service;
    GoogleAccessProtectedResource accessProtectedResource = new GoogleAccessProtectedResource(null);

    // TODO(yanivi): save auth token in preferences?
    GoogleAccountManager accountManager;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        JacksonFactory jack = new JacksonFactory();
        //service = new Tasks(transport, accessProtectedResource, new JacksonFactory());
        //service.setKey(/* my auth key goes here */);
        //service.setApplicationName("tasks");

        accountManager = new GoogleAccountManager(this);
    }
}

I am using netbeans (without maven) and didn't modify my AndroidManifest.xml by hand, yet.

Edit:
The libraries I'm including via the project's libs dir are:

Thanks for any help in advance.

Upvotes: 0

Views: 1679

Answers (2)

CAM-Dev
CAM-Dev

Reputation: 186

I had the same problem with the 1.4.1 files. The solution for my situation was to: Right click my project, then Build Path>Configure Build Path, then under Java Build Path, select all of the jar files, then press the OK button.

After that, I worked.

Upvotes: 0

PureSpider
PureSpider

Reputation: 407

Upgrading to Google Client libraries 1.5.0 beta fixed it, my libs folder now looks like so:

  • google-api-client-1.5.0-beta.jar
  • google-api-client-extensions-1.5.0-beta.jar
  • google-api-client-extensions-android2-1.5.0-beta.jar
  • google-api-services-tasks-v1-1.2.0-beta.jar
  • google-http-client-1.5.0-beta.jar
  • google-http-client-extensions-1.5.0-beta.jar
  • google-http-client-extensions-android2-1.5.0-beta.jar
  • google-oauth-client-1.5.0-beta.jar
  • google-oauth-client-extensions-1.5.0-beta.jar
  • guava-r09.jar
  • jackson-core-asl-1.6.7.jar

I also had to add
<uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission> <uses-permission android:name="android.permission.USE_CREDENTIALS"></uses-permission>
to my AndroidManifest.xml
Hope that helps anyone out there having the same problems!
Also see http://code.google.com/p/buzz-java-client/issues/detail?id=18 for reference.

Upvotes: 3

Related Questions