Android O Preview: Remote ConnectivityManager methods do not support backward compatibility

Prerequisite and build configuration: I am trying to create my application with an overview of AndroidStudio 2.4 5 by setting the build configuration below for an O perview device for Android, compileSdkVersion 'android-O' buildToolsVersion '25 .0.0 'compileOptions.encoding =' ISO-8859- 1 'minSdkVersion 16 targetSdkVersion' O '// Enable multidex support. multiDexEnabled true

Problem Description: My application uses these legacy ConnectivityManager class methods for devices with an older version of Android. - ConnectivityManager.startUsingNetworkFeature() - ConnectivityManager.stopUsingNetworkFeature() -ConnectivityManager.requestRouteToHost()

When I try to create my application with the above api, it gives a compile-time error as follows:

Error: (626, 48) error: cannot find startUsingNetworkFeature (int, String) character method Error: (7393, 27) error: cannot find stopUsingNetworkFeature (int, String) character method Error: (69, 36) error: not unable to find requestRouteToHost character method (int, int)

Ideally, these api should not give a compile-time error for the purpose of the reverse goal. Please let me know how to solve these compile-time errors.

I can’t remove these methods from the code, because they are necessary for devices with the old version of Android (less than the version of Android L)

+4
source share
3 answers

Android . , compileSdkVersion 25. :

@SuppressWarnings("Deprecation")
public class NetworkFeaturesCompat {
    public static NetworkFeaturesCompat from(final ConnectivityManager cm) {
        return new NetworkFeaturesCompat(cm);
    }

    private final ConnectivityManager mConnectivityManager;

    private NetworkFeaturesCompat(final ConnectivityManager cm) {
        mConnectivityManager = cm;
    }

    public int startUsingNetworkFeature(final int networkType, final String feature) {
        return mConnectivityManager.startUsingNetworkFeature(networkType, feature);
    }

    public int stopUsingNetworkFeature(final int networkType, final String feature) {
        return mConnectivityManager.stopUsingNetworkFeature(networkType, feature);
    }

    public boolean requestRouteToHost(final int networkType, final int hostAddress) {
        return mConnectivityManager.requestRouteToHost(networkType, hostAddress);
    }
}

, build.gradle:

dependencies {
    compile project(":your-new-library-module-name")
}

.

.

, proguard ( ):

-dontwarn android.net.ConnectivityManager

, UnsupportedOperationException Android 6 +.

?

SDK, API SDK 26. .

SDK 25, API. .

SDK 26, proguard . .

+3

Android L startUsingNetworkFeature, stopUsingNetworkFeature, requestRouteToHost .

Google .

0

Make sure your library module has compileSdkVersion 25.

0
source

Source: https://habr.com/ru/post/1674643/


All Articles