Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update deprecated com.google.api.client.extensions.android.http.AndroidHttp

I have the follow object

HttpTransport t = AndroidHttp.newCompatibleTransport();

but whole AndroidHttp class (com.google.api.client.extensions.android.http.AndroidHttp) is marked as deprecated.

I don't know what is the class that replaces this, using newer libraries.

How could I replace this obsolete call?

like image 288
AndreaF Avatar asked Feb 09 '19 13:02

AndreaF


People also ask

How do I use the googleapiclient?

You can use the GoogleApiClient("Google API Client") object to access the Google APIs provided in the Google Play services library (such as Google Sign-In, Games, and Drive). The Google API Client provides a common entry point to Google Play services and manages the network connection between the user's device and each Google service.

How does the API update the location of my App?

In response, the API updates your app periodically with the best available location, based on the currently-available location providers such as WiFi and GPS (Global Positioning System). The accuracy of the location is determined by the providers, the location permissions you've requested, and the options you set in the location request.

How do I manage the connection between threads and Google APIs?

The simplest way to manage the connection is to use GoogleApiClient.Builder.enableAutoManage (FragmentActivity, GoogleApiClient.OnConnectionFailedListener). See Accessing Google APIs. GoogleApiClient instances are not thread-safe. To access Google APIs from multiple threads simultaneously, create a GoogleApiClient on each thread.

Is googleapiclient thread-safe?

GoogleApiClient instances are not thread-safe. To access Google APIs from multiple threads simultaneously, create a GoogleApiClient on each thread. GoogleApiClient service connections are cached internally, so creating multiple instances is fast. This class is deprecated. Use GoogleApi based APIs instead. See Moving Past GoogleApiClient.


1 Answers

This link tells us that prior to Gingerbread the HttpURLConnection implementation was buggy and Apache HTTP Client was preferred.

However this has been fixed for newer versions and now new NetHttpTransport() can be used directly. So just use: HttpTransport t = new NetHttpTransport(); and you should be fine.

This is also what newCompatibleTransport does behind the curtain:

public static HttpTransport newCompatibleTransport() { return AndroidUtils.isMinimumSdkLevel(9) ? new NetHttpTransport() : new ApacheHttpTransport(); }

like image 121
Rene Ferrari Avatar answered Oct 07 '22 01:10

Rene Ferrari