I’m creating an Android app and trying to use Google Places API through Google APIs Client. I’ve been following this example:
http://ddewaele.blogspot.com/2011/05/introducing-google-places-api.html
I’m having problems creating a HTTP Transport Object to use in creating the HTTP Request Factory. Everything compiles fine in eclipse, but when I debug while running on my phone, I get a classnotfound on the first line here:
HttpTransport transport = new ApacheHttpTransport();
HttpRequestFactory httpRequestFactory = createRequestFactory(transport);
public static HttpRequestFactory createRequestFactory(HttpTransport transport) {
return transport.createRequestFactory(new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
request.headers.authorization = "...";
}
});
}
According to the JavaDoc for the HTTP Transport Class:
Android:
- Starting with SDK 2.3, strongly recommended to use
com.google.api.client.javanet.NetHttpTransport. Their Apache HTTP Client
implementation is not as well maintained.- For SDK 2.2 and earlier, use com.google.api.client.apache.ApacheHttpTransport.
com.google.api.client.javanet.NetHttpTransport
is not recommended due to some bugs in
the Android SDK implementation of
HttpURLConnection.
I’m running on 2.2, so I tried using the ApacheHTTPTransport. I’ve also tried the NetHTTPTransport, but I get the same thing (classnotfound).
Any ideas/examples?
Thanks!
In order to run the Places API in an Android environment using the Google APIs Client, you’ll need to have the following dependencies in your Android project :