Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

com.google.api.client.extensions.android.http.androidhttp is deprecated

Hello I try to communicate with google drive api on android app, but I see this deprecated by google, how I solve this to my code?

    void fun(GoogleSignInAccount signInAccount){
    Log.d("jjj","fun called");
    GoogleAccountCredential credential =
            GoogleAccountCredential.usingOAuth2(
                    this, Collections.singleton(DriveScopes.DRIVE_FILE));
    credential.setSelectedAccount(signInAccount.getAccount());
    Drive googleDriveService =
            new Drive.Builder(
                    AndroidHttp.newCompatibleTransport(),
                    new GsonFactory(),
                    credential)
                    .setApplicationName("Drive API Migration")
                    .build();
    editor.putBoolean("SyncOn",true).commit();
    mDriveServiceHelper = new DriveServiceHelper(googleDriveService);

picture with problem: deprecated code picture - line problem

like image 514
mahmooddtek Avatar asked Sep 07 '26 21:09

mahmooddtek


1 Answers

Instead of AndroidHttp, use NetHttpTransport directly or switch to Cronet which is better supported.

Drive googleDriveService = new Drive.Builder(
        new NetHttpTransport(),
        new GsonFactory(),
        credential)
    .setApplicationName("Drive API Migration")
    .build();

Reference: https://github.com/googleapis/google-http-java-client/blob/master/google-http-client-android/src/main/java/com/google/api/client/extensions/android/http/AndroidHttp.java#L35

like image 147
Saurabh Thorat Avatar answered Sep 10 '26 10:09

Saurabh Thorat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!