achie
achie

Reputation: 4746

How to check if background data is enabled on the android?

I want to check if the user enabled background data on his/her device and display a message if it is disabled.

How can I check if it has been enabled? I tried

import android.provider.Settings;

//...
Settings.System.getString(getContentResolver(), Settings.Secure.BACKGROUND_DATA);
//and
Settings.Secure.getString(getContentResolver(), Settings.Secure.BACKGROUND_DATA);

But they are returning null.

Thank you, Achie.

Upvotes: 7

Views: 3636

Answers (1)

Jess
Jess

Reputation: 42948

You want to use the Connectivity Manager to get this info.

ConnectivityManager mgr = (ConnectivityManager)Context.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean bgData = mgr.getBackgroundDataSetting();

Upvotes: 11

Related Questions