Issue retrieving ConnectivityManager in a device with multi sim
Asked Answered
D

2

9

I am having an issue getting ConnectivityManager:

ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

I am using the application context, and I get this error:

Caused by: java.lang.NullPointerException: missing IConnectivityManager
at com.android.internal.util.Preconditions.checkNotNull(Preconditions.java:52)
at android.net.ConnectivityManager.<init>(ConnectivityManager.java:1045)
at android.net.MultiSimConnectivityManager.<init>(MultiSimConnectivityManager.java:86)
at android.app.ContextImpl$12.createService(ContextImpl.java:463)
at android.app.ContextImpl$ServiceFetcher.getService(ContextImpl.java:346)
at android.app.ContextImpl.getSystemService(ContextImpl.java:2036)
at android.content.ContextWrapper.getSystemService(ContextWrapper.java:551)

Have you seen this issue? Is there any way to solve it?

Thanks, Diego.

Displant answered 27/10, 2014 at 13:9 Comment(4)
May be this context is null please check thisRacemic
also check the manifest permissionRacemic
I am calling context.getApplicationContext(), it must not be null. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> is there.Kudos
Can you please post the full code.@Diego Gomez OlveraSubclimax
B
0

Connectivity Service is null.

public ConnectivityManager(Context context, IConnectivityManager service) {
    mContext = checkNotNull(context, "missing context");
    mService = checkNotNull(service, "missing IConnectivityManager");
    sInstance = this;
}

Please check if Connectivity Service is running on your device.

adb shell service list | grep connectivity
13      connectivity_metrics_logger: [android.net.IConnectivityMetricsLogger]
64      connectivity: [android.net.IConnectivityManager]
Boisleduc answered 8/3, 2017 at 6:36 Comment(0)
D
0

if you are facing such issue of IconnectivityManager, then you might be getting the context null, at some point or in some cases., Since you might be doing this in a service where context might be null thus, you can do one thing such as:

 if (context != null) {
        ConnectivityManager cm =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

something like this>>

Druci answered 25/7, 2017 at 4:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.