Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 446
achie Avatar asked Dec 20 '10 22:12

achie


People also ask

What happens if I disable background data?

So when you restrict the background data, the apps will no longer consume the internet in the background, i.e. while you are not using it. It will use the internet only when you open an app. This even means you won't get real-time updates and notifications when the app is closed.


1 Answers

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

ConnectivityManager mgr = (ConnectivityManager)Context.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean bgData = mgr.getBackgroundDataSetting();
like image 140
Jess Avatar answered Nov 03 '22 14:11

Jess