thegrizzlylabs / sardine-android

A WebDAV library for Android
Apache License 2.0
355 stars 70 forks source link

Support for Android 4.x #40

Closed 3c71 closed 4 years ago

3c71 commented 4 years ago

I'm trying to use this library on an app with a minimum SDK of 14, and it appears to work fine, appart from one method in AuthenticationIntercepter, which only support API 19 and above:

To fix this I've added a special method to get UTF8 standard charset:

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request()
            .newBuilder()
            .addHeader("Authorization", Credentials.basic(userName, password, standardUTF8()))
            .build();
        return chain.proceed(request);
    }

The method to get a standard charset is as follows:

    public static Charset standardUTF8()
    {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
        {
            return StandardCharsets.UTF_8;
        }
        else
        {
            //noinspection CharsetObjectCanBeUsed
            return Charset.forName("UTF-8");
        }
    }
guillaume-tgl commented 4 years ago

Great. Feel free to open a PR with this change so that we can review it.

3c71 commented 4 years ago

Opened my first PR, hope I've done it right? Don't have git on my windows PC, so I made the modifications from github.

guillaume-tgl commented 4 years ago

Fixed by #41