我正在开发Android Honeycomb(v3.0)应用程序,该应用程序需要与Google Calendar API进行通信.我想允许我的应用访问特定Google帐户的日历数据,以便阅读和创建活动.
不幸的是,我使用OAuth2遇到授权问题.这是我到目前为止所拥有的:
1)我想访问其日历的Google帐户是在我正在使用的Android设备中注册的.
2)我在帐户的Google API控制台中启用了Calendar API.
3)我可以使用以下代码访问此帐户:
AccountManager accountManager = AccountManager.get(this.getBaseContext());
Account[] accounts = accountManager.getAccountsByType("com.google");
Account acc = accounts[0]; // The device only has one account on it
Run Code Online (Sandbox Code Playgroud)
4)我现在想要获得一个AuthToken,以便在与日历通信时使用.我遵循了本教程,但将所有内容转换为适用于Google日历而非Google任务.我通过使用with 成功authToken从AccountManager我想要使用的帐户中检索一个.getAuthTokenAUTH_TOKEN_TYPE == "oauth2:https://www.googleapis.com/auth/calendar"
5)这是问题开始的地方.我现在在这一点上:
AccessProtectedResource accessProtectedResource = new GoogleAccessProtectedResource(tokens[0]); // this is the correct token
HttpTransport transport = AndroidHttp.newCompatibleTransport();
Calendar service = Calendar.builder(transport, new JacksonFactory())
.setApplicationName("My Application's Name")
.setHttpRequestInitializer(accessProtectedResource)
.build();
service.setKey("myCalendarSimpleAPIAccessKey"); // This is deprecated???
Events events = service.events().list("primary").execute(); // …Run Code Online (Sandbox Code Playgroud) android google-calendar-api google-api google-api-java-client android-3.0-honeycomb
我正在尝试按照以下示例编写每周日历:
如何为 Android Honeycomb 应用程序创建每周日历视图?
我已经在 XML 文件中添加了一条时间标记行,该行假设在当前小时。为此,我使用:
<LinearLayout
android:id="@+id/currentTimeMarkerLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="120dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="0dp" >
<View
android:layout_width="0dp"
android:layout_height="3dp"
android:layout_weight="1" />
<View
android:id="@+id/currentTimeLineView"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="14"
android:background="@color/dark_blue" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这LinearLayout是在 aRelativeLayout里面,它们都在 a 里面ScrollView。
我试图通过编程来“移动”这一行,方法是修改layout_margintTop这些行:
int dipValue = 720; // we want to convert this dip value to pix
Resources r = getResources();
float pix = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
dipValue, r.getDisplayMetrics());
LinearLayout lay =(LinearLayout) findViewById(R.id.currentTimeMarkerLinearLayout);
LinearLayout.LayoutParams lp = lay.getLayoutParams();
lp.setMargins(0, (int) pix, 0, …Run Code Online (Sandbox Code Playgroud)