forked from google/google-api-java-client-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstructions.html
More file actions
179 lines (164 loc) · 7.75 KB
/
Copy pathinstructions.html
File metadata and controls
179 lines (164 loc) · 7.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<html>
<title>calendar-android-sample</title>
<body>
<h2>Instructions for the Calendar V3 Android Sample</h2>
<h3>Warning</h3>
This sample is for illustrative purposes. Please consider using the native
<a
href="http://developer.android.com/guide/topics/providers/calendar-provider.html">Calendar
Provider API</a>.
<h3>Browse Online</h3>
<ul>
<li><a
href="https://github.com/google/google-api-java-client-samples/tree/master/calendar-android-sample">Browse
Source</a>, or main file <a
href="https://github.com/google/google-api-java-client-samples/tree/master/calendar-android-sample/src/main/java/com/google/api/services/samples/calendar/android/CalendarSampleActivity.java">CalendarSampleActivity.java</a>
</li>
</ul>
<h3>Prerequisites</h3>
<ul>
<li>Install <a href="http://java.com">Java</a> (requires 6 or higher)</li>
<li>Install <a href="http://git-scm.com/downloads">Git</a> (suggested 1.7.10 or higher)
or <a href="http://github.com">GitHub</a> client (<a href="http://mac.github.com/">Mac</a>)
(<a href="http://windows.github.com/">Windows</a>)</li>
<li>Unzip <a href="http://services.gradle.org/distributions/gradle-2.2.1-bin.zip">Gradle
2.2.1</a></li>
<li>Install either <a
href="http://developer.android.com/sdk/installing/studio.html">Android
Studio</a> (which bundles the Android SDK) or just <a
href="http://developer.android.com/sdk/index.html">Android SDK</a> if you don't want to
use Android Studio. Set your
ANDROID_HOME to the Android SDK installation directory, which for Android Studio is in the
"sdk" subdirectory.
</li>
</ul>
<h3>Register Your Application</h3>
<ul>
<li>Visit the <a
href="https://cloud.google.com/console/start/api?id=calendar">Google Cloud
console flow for the Google Calendar API</a>.
</li>
<li>If necessary, sign in to your Google Account, select or create a
project, and agree to the terms of service. Click Continue.
</li>
<li>For Platform select "Android".
<ul>
<li>For "Package name" you should make up a unique name that has never been used before
by anyone, e.g. using your name and date like
"org.example.calendar.janedoe20130911".
<ul>
<li><b>Note:</b> Make
sure to pick a legal Java package name since we will be using it in the
Android
project source code. The full package name must have at least two parts, so
for example "janedoe20130911" will not work.
</li>
<li><b>Note:</b> If you try
to register a package name that has already been registered, you may get an
error reading "An
unexpected error has occurred." In particular,
"com.google.api.services.samples.calendar.android" has already been
registered, so you must change the package name.
</li>
</ul>
</li>
<li>For "SHA1 fingerprint", use the value that is output when running this command in a
Terminal:
<pre>
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1
</pre>
When asked, use "android" (without the quotes) as the keystore password.
</li>
<li>Click Register.</li>
</ul>
</li>
<li>Click on "APIs" under "APIs & auth" in the left sidebar and make sure "Calendar API" is
enabled.
</li>
</ul>
<h3>Checkout Instructions</h3>
<pre>
cd <i>[someDirectory]</i>
git clone https://github.com/google/google-api-java-client-samples.git
cd google-api-java-client-samples/calendar-android-sample
</pre>
<h3>Set Up Project in Android Studio</h3>
<ul>
<li>Run the <a href="http://developer.android.com/tools/help/sdk-manager.html">Android SDK
Manager</a>:
<ul>
<li>Run this command in a terminal:
<pre>$ANDROID_HOME/tools/android sdk</pre>
</li>
<li>Under "Tools", check on "Android SDK Build-tools" revision 22.0.1.</li>
<li>Under "Android 5.1.1 (API 22)", check on "SDK Platform" and "Google APIs".</li>
<li>Under "Extras", check on "Android Support Repository", "Android Support Library",
and "Google Repository".
</li>
<li>Click on "Install X packages..."</li>
</ul>
</li>
<li>Start Android Studio by running this command in a terminal:
<pre>android-studio/bin/studio.sh</pre>
</li>
<li>Import <code>calendar-android-sample</code> project
<ul>
<li>Select "Import Project..." or File > Import Project...</li>
<li>Select <code>
<i>[someDirectory]</i>/google-api-java-client-samples/build.gradle
</code> and click OK.
<ul>
<li><b>Note:</b> it will not work if you try to import <code>
<i>[someDirectory]</i>/google-api-java-client-samples/calendar-android-sample/build.gradle
</code>.
</li>
</ul>
</li>
<li>Select "Use local gradle distribution" with "Gradle home" of
<code><i>[someDirectory]</i>/gradle-2.2.1</code> and click OK.
</li>
</ul>
</li>
<li>Open AndroidManifest.xml and change the package attribute of the manifest, initially
"com.google.api.services.samples.calendar.android", to match the name you registered in the
Google Cloud Console, e.g. "org.example.calendar.janedoe20130911".
</li>
<li>Rename the Java package: right-click on src/main/java, click New, click Package, and then
enter the name you registered in the
Google Cloud Console, e.g. "org.example.calendar.janedoe20130911". Next, select the Java
classes in
the package "com.google.api.services.samples.calendar.android", drag them into the new
package
you just created, and then click Refactor.
<ul>
<li><b>Note:</b> If you get a compile error for "R", try right-clicking on the Java
package and then clicking "Optimize Imports" to remove unused imports containing the
"R". Another possibility is that the
"package" in the AndroidManifest.xml file doesn't match the Java package name.
</li>
</ul>
</li>
<li>Run > Run 'calendar-android-sample'
<ul>
<li><b>Note:</b> you must use a physical device for developing and testing
because Google Play services cannot be installed on an emulator.
<a href="http://developer.android.com/training/basics/firstapp/running-app.html#RealDevice">
Read this page</a> for more information on how to set up a device.
</li>
<li>To enable logging of HTTP requests and responses (highly recommended
when developing):
<pre>
$ANDROID_HOME/platform-tools/adb shell setprop log.tag.HttpTransport DEBUG
</pre>
and then change <code>CalendarSampleActivity.LOGGING_LEVEL</code> to <code>Level.CONFIG</code>.
</li>
<li><b>Note:</b> If get "[Error] Access Not Configured" it usually means the Android app
registration didn't work or doesn't match your app's package name and SHA1
fingerprint. It may also be because "Calendar API" isn't enabled for your project
in the Google Cloud Console (see instructions above).
</li>
</ul>
</li>
</ul>
</body>
</html>