尝试在 Android 上使用 Google Tasks API 让我的应用程序崩溃
我正在尝试使用 Google Tasks API 为 Android 构建一个简单的待办事项应用程序。
然而,无论我尝试更改或包含什么,我的应用程序都可以正常编译,但每当我尝试使用任务 API 时,它就会在手机上崩溃。
所有库都在我的 libs 文件夹中,但我不知道我还需要包含哪些依赖项。 这是我当前的代码,一旦我删除任务行的注释,我的应用程序在手机上打开后就会崩溃。
杰克的事情是为了测试 JacksonFactory 不是错误。
问题可能是我正在调用 new GoogleAccessProtectedResource(null) ,它必须使用 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);
}
}
我正在使用netbeans(没有maven)并且还没有手动修改我的AndroidManifest.xml。
编辑:
我通过项目的 libs 目录包含的库是:
- google-api-client-1.4.1-beta.jar
- google-api-client-extensions-1.4.1-beta.jar
- google-api-client-extensions-android2 -1.4.1-beta.jar
- google-api-client-googleapis-1.4.1-beta.jar
- google-api-client-googleapis-extensions-1.4.1-beta.jar
- google-api-client-googleapis-extensions-android2-1.4.1-beta.jar
- google-api-services-tasks-v1-1.2.0- beta.jar gson-1.6.jar
- guava-r09.jar
- httpclient-4.0.3.jar
- jackson-core-asl-1.6.7.jar
感谢提前提供任何帮助。
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:
- google-api-client-1.4.1-beta.jar
- google-api-client-extensions-1.4.1-beta.jar
- google-api-client-extensions-android2-1.4.1-beta.jar
- google-api-client-googleapis-1.4.1-beta.jar
- google-api-client-googleapis-extensions-1.4.1-beta.jar
- google-api-client-googleapis-extensions-android2-1.4.1-beta.jar
- google-api-services-tasks-v1-1.2.0-beta.jar gson-1.6.jar
- guava-r09.jar
- httpclient-4.0.3.jar
- jackson-core-asl-1.6.7.jar
Thanks for any help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
升级到 Google 客户端库 1.5.0 beta 修复了这个问题,我的 libs 文件夹现在看起来像这样:
我还必须添加
;
;
到我的 AndroidManifest.xml
希望对遇到同样问题的人有所帮助!
另请参阅 http://code.google.com/p /buzz-java-client/issues/detail?id=18 供参考。
Upgrading to Google Client libraries 1.5.0 beta fixed it, my libs folder now looks like so:
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.
我对 1.4.1 文件也有同样的问题。针对我的情况的解决方案是:
右键单击我的项目,然后选择“构建路径”>“配置构建路径”,然后在“Java 构建路径”下选择所有 jar 文件,然后按“确定”按钮。
之后我就工作了。
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.