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?
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.
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.
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.
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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With