你的问题是最新的还是你已经解决了你的问题?
编辑:
这里有一些基本信息如何实现 GoogleCalendar:
1.创建一个类来处理日历:
public class MyCalendar
{
private static final String AUTH_TOKEN_TYPE = "cl";
public static final String KEY = "YOUR_API_KEY"; //You can find below Simple API Access at GoogleApiConsole
final HttpTransport transport = AndroidHttp.newCompatibleTransport();
final JsonFactory factory = new GsonFactory();
GoogleAccountManager accountManager;
String name;
String token;
public com.google.api.services.calendar.Calendar mycalendar;
private HttpRequestInitializer initializer = new HttpRequestInitializer()
{
public void initialize(HttpRequest request) throws IOException
{
request.getHeaders().setAuthorization(GoogleHeaders.getGoogleLoginValue(authToken));
}
};
public MyCalendar()
{
}
}
创建一个日历对象(我在 MyCalendar 的构造函数中执行此操作
mycalendar = com.google.api.services.calendar.Calendar.builder(transport,jsonFactory)
.setApplicationName("CHOOSE_A_APPNAME")
.setHttpRequestInitializer(initializer)
.setJsonHttpRequestInitializer(new GoogleKeyInitializer(KEY))
.build();
accountManager = new GoogleAccountManager(TimetableApplication.getInstance().getActivity());
findGoogleAcc();
如果您想访问您的日历,初始化程序的初始化方法 [;-)] 将在稍后调用。
2.搜索用户手机所指的GoogleAccount
void findGoogleAcc()
{
Account account = accountManager.getAccountByName(name);
if(account == null)
{
//Handle wrong name, or if user connect more than one accounts to phone
}
if(token != null)
{
//you already got your token for user's account and these method is not necessary
}
accountManager.getAccountManager().getAuthToken(account, AUTH_TOKEN_TYPE, true, new AccountManagerCallback<Bundle>() {
public void run(AccountManagerFuture<Bundle> future)
{
try
{
Bundle bundle = future.getResult();
if(bundle.containsKey(AccountManager.KEY_INTENT))
{
// Allow app to connect to googleaccount
Intent intent = bundle.getParcelable(AccountManager.KEY_INTENT);
intent.setFlags(intent.getFlags() & ~ Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivityForResult(intent, 0);
}
else
if(bundle.containsKey(AccountManager.KEY_AUTHTOKEN))
{
this.authToken = authToken;
gotSmthFromCalendar();
}
}
catch(Exception e)
{
}
}
}, null);
}
3.在方法上使用您的日历:
void gotSmthFromCalendar()
{
//Here u can do whatever u want.
}
我认为在 gotSmthFromCalendar() 上,您应该使用 AsyncTask 来请求数据。例如你可以这样做:
List<CalendarListEntry> calendarList = mycalendar.calendarList().list().execute().getItems();
for(CalendarListEntry calendarEntry : calendarList)
{
String summary = calendarEntry.getSummary();
String id = calendarEntry.getId();
Log.v("Calendar","Found a calendar with summary : " + summary + " an id: " + id);
}
希望这些基础知识可以帮助您使用 v3。如果你需要额外的帮助,每次都问我!!
小木