Show in activity message from BroadcastReceiver when change connectivity - android

I have BroadCastReceiver that control my connectivity.
I would, when I lost connection, show message, but not generic toast, but a "layout" that I designed.
my broadcast is a generic broadCast for connection:
public class ConnectivityChangeReceiver extends BroadcastReceiver {
#Override
public void onReceive(final Context context, final Intent intent) {
ConnectivityManager cm =(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm.getActiveNetworkInfo()!=null){
Toast.makeText(context, "Connected to Internet", Toast.LENGTH_LONG).show();
}
else{
/** HERE INSTEAD OF TOAST, IWOULD DISPLAY MESSAGE ON ACTIVITY **/
Toast.makeText(context, "not connection", Toast.LENGTH_LONG).show();
Log.i("INTERNET", "---------------------> Internet Disconnected. ");
}
}
}
And my "no_connection_layout"
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="52dp"
android:text="No InterNeT"
android:id="#+id/no_connection"
android:layout_weight="1"
android:layout_gravity="center|top"
android:gravity="center"
android:background="#android:color/holo_green_dark"
android:textStyle="bold"
android:textColor="#ffffff"
/>
</FrameLayout>
Is there a way for show this layout indistinctly current activity?

#Override
public void onReceive(final Context context, final Intent intent) {
//Obviously cleanup where you do this stuff, to make it efficient
//If your context is a fragment you need to cast to fragment and then do getActivity instead
final View noConnectionBanner = ((Activity) context).findViewById(R.id.no_connection)
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm.getActiveNetworkInfo() != null) {
noConnectionBanner.setVisibility(View.GONE);
} else {
noConnectionBanner.setVisibility(View.VISIBLE);
}
}

Just trigger a function and write the view elements that you want to show.
public class ConnectionBroadReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager cm = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
} else {
Visibler();
}
}
}
#Override
protected void onResume() {
this.connectionBroadReceiver = new ConnectionBroadReceiver();
registerReceiver(this.connectionBroadReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
super.onResume();
}
#Override
protected void onPause() {
unregisterReceiver(this.connectionBroadReceiver);
super.onPause();
}
Then inside main program,
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
floatingActionButton = (FloatingActionButton) findViewById(R.id.floater);
}
private void Visibler() {
floatingActionButton.setVisibility(View.VISIBLE);
}

Create a Global Boolean and make it true when There is internet Connectivity and false when it is not connected.
And then create a async task class doinBackground method and check it continuosly when the variable changes and from postExecute method you can make changes in the UI. if you need more help pm me .

Related

Should I check connectivity in every activity in Android?

So I just implemented a checking connectivity method, but should I do this for every activity? Is there a simpler way to continually check for connectivity?
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager cm =
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
return isConnected;
}
First create a ConnectivityChangeReceiver like the following:
public class ConnectivityChangeReceiver extends BroadcastReceiver {
private OnConnectivityChangedListener listener;
public ConnectivityChangeReceiver(OnConnectivityChangedListener listener) {
this.listener = listener;
}
#Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager connectivityManager = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
boolean isConnected = activeNetInfo != null && activeNetInfo.isConnectedOrConnecting();
listener.onConnectivityChanged(isConnected);
}
public interface OnConnectivityChangedListener {
void onConnectivityChanged(boolean isConnected);
}
}
Then create a BaseActivity which extends all of your activites:
public class BaseActivity extends Activity implements OnConnectivityChangedListener {
private ConnectivityChangeReceiver connectivityChangeReceiver;
#Override
public void onCreate(Bundle savedInstanceState) {
connectivityChangeReceiver = new ConnectivityChangeReceiver(this);
IntentFilter filter = new IntentFilter();
filter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
registerReceiver(connectivityChangeReceiver, filter);
}
#Override
public void onConnectivityChanged(boolean isConnected) {
// TODO handle connectivity change
}
#Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(connectivityChangeReceiver);
}
}
(If you don't want a BaseActivity, you can implement OnConnectivityChangedListener in all of your activities. But in that case you have to register the receiver in all of your Activity.)
You can check this out: This is service that will continuously check the connection. This will be the proper way to do it
`private void installListener() {
if (broadcastReceiver == null) {
broadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
NetworkInfo info = (NetworkInfo) extras
.getParcelable("networkInfo");
State state = info.getState();
Log.d("InternalBroadcastReceiver", info.toString() + " "
+ state.toString());
if (state == State.CONNECTED) {
onNetworkUp();
} else {
onNetworkDown();
}
}
};
final IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(broadcastReceiver, intentFilter);
}
}`
Look on this link: Android service to check internet connectivity?
Create some sort of util class, for example ConnectionUtils.
Add a public static method to that class and add a Context object to the parameters. For example:
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
return isConnected;
}
Then in your Activity just call ConnectionUtils.isNetworkAvailable(this) to know if you're connected.
It would even be better to create some sort of base Activity that you extend with this method in it.
public abstract class BaseActivity extends Activity {
protected boolean isConnected() {
return ConnectionUtils.isNetworkAvailable(this);
}
}
And then let all your Activities extend BaseActivity instead of Activity
You should check before every request to the internet! The user can terminate the connection at any given time... even while your Activity is running.
I suggest you make an Utils class and put this method inside and make it public static so you can access it from everywhere within the Application.
I say it is better to check before every request. It might happen that the connection got broken in between. So its not wise to rely on a check sometime earlier

Updating Wifi status info at regular intervals in android

I know this question might be replica of another question but can someone help me figure out where I have gone wrong and possibly correct it if possible?
public class MainActivity extends ActionBarActivity {
TextView ford;
public String TAG=MainActivity.class.getSimpleName();
protected static final long TIME_DELAY = 1000;
//the default update interval for your text, this is in your hand , just run this sample
TextView mTextView;
Handler handler=new Handler();
Random trust = new Random();
int count =0;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView=(TextView)findViewById(R.id.textview);}
protected void onResume({
super.onResume();handler.post(updateTextRunnable);}
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
Runnable updateTextRunnable=new Runnable(){
public void run() {
if (networkInfo != null && networkInfo.isConnected()) {
mTextView.setText("connected!");
} else {
mTextView.setText("No network connection available.");
}
}
};
}
Efficient way is to create a broacast receiver which will reguralry check wifi status. Register receiver like this-
WifiMonitor wifiMonitor = new WifiMonitor();
registerReceiver(wifiMonitor, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
registerReceiver(wifiMonitor, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
public class WifiMonitor extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
//do your work here
}
}

how to display text message in app when device is Network is off and On

public class MainActivity extends ActionBarActivity {
TextView connectionchecktextbox;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
connectionchecktextbox = (TextView) findViewById(R.id.connectionchecktextbox);
if (Utils.isNetworkAvailable(MainActivity.this)) {
connectionchecktextbox.setVisibility(View.GONE);
}
else {
connectionchecktextbox
.setText("It Seems Internet Connection if off");
}
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.popupdisplay.MainActivity$PlaceholderFragment" >
<TextView
android:id="#+id/connectionchecktextbox"
android:layout_width="fill_parent"
android:layout_height="25dip"
android:layout_alignParentBottom="true"
android:background="#F40C0C"
android:gravity="center"
android:text="It Seems Internert Connection if off"
android:textAlignment="gravity"
android:textColor="#ffffff" />
</RelativeLayout>
here is Xml
Using this code i am able to display Text message when device is Internet off and On but it display when we open app : means we have to call always on create to show this i want automatic text message should display when app is On then text message should disappear and when off then automatic that text message should appear please tell me how i to apply this
public class NetworkReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
boolean isConnected = activeNetwork != null
&& activeNetwork.isConnectedOrConnecting();
if (isConnected == true) {
// initChatHub();
Toast.makeText(context, "Connected", 1000).show();
} else {
Toast.makeText(context, "Disconnected", 1000).show();
}
}
Try this simple code and enjoy if any Query please inform me.
I think you should use Toast for that.
Heres how to use it.
Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
You can use a BroadcastReceiver to do this. The broadcast receiver inform's you about any connectivity changes:
public class InternetBroadcastReceiver extends BroadcastReceiver
public static boolean iAmOnline = false;
{
#Override
public void onReceive(Context context, Intent intent) {
if (isOnline(context))
{
iAmOnline = true;
Toast.makeText(context, "Network Available Do operations",Toast.LENGTH_LONG).show();
}else{
iAmOnline = false;
}
}
public boolean isOnline(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
//should check null because in air plan mode it will be null
if (netInfo != null && netInfo.isConnected()) {
return true;
}
return false;
}
}
}
And register InternetBroadcastReceiver in your manifest file:
<receiver android:name=".InternetBroadcastReceiver" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
In any place in your app you can now check the internet connection using InternetBroadcastRectiver.iAmOnline. :

Check Android Network continuously

I want to verify the Android system networks continuously in this way, but i think that in this form is not correct, my service should update if the connection on wifi or other network is available.
public class ObjService extends Service{
private final static int NOTIFICATION=1;
public static boolean process;
private NotificationManager state;
private NotificationCompat.Builder objBuilder;
public void onCreate(){
process=true;
state=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
objBuilder = new NotificationCompat.Builder(this)
.setContentTitle("Title")
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.launchimg))
.setSmallIcon(R.drawable.notification_img);
Thread checker=new Thread(){//1
public void run(){//2
while (process){//3
if (verifyConnection()){//4
updateNotificationService("Service is available");
}else{
updateNotificationService("Service is not available");
}//4
try{
Thread.sleep(6000);
}catch(InterruptedException e){
//..printLog..
}
}//3
};//2
};//1
checker.start();
.
.
.
my function verifyConnection() is:
public boolean verifyConnection() {
boolean flag = true;
ConnectivityManager connec = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] net = connec.getAllNetworkInfo();
if (!net[0].isAvailable() && !net[1].isAvailable())
{
flag = false;
}
return flag;
}
updateNotificationService() is:
public void updateNotificacionService(String arg){
objBuilder.setContentText(arg)
.setWhen(System.currentTimeMillis());
state.notify(NOTIFICATION, objBuilder.build());
}
Try this code below to listen whether the connection exist, if the connection state changes it notifies the change,
public class NetworkStateReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
Log.d("app","Network connectivity change");
if(intent.getExtras()!=null) {
NetworkInfo ni=(NetworkInfo) intent.getExtras().get(ConnectivityManager.EXTRA_NETWORK_INFO);
if(ni!=null && ni.getState()==NetworkInfo.State.CONNECTED) {
Log.i("app","Network "+ni.getTypeName()+" connected");
}
}
if(intent.getExtras().getBoolean(ConnectivityManager.EXTRA_NO_CONNECTIVITY,Boolean.FALSE)) {
Log.d("app","There's no network connectivity");
}
}
}
Then for manifest,
<receiver android:name=".NetworkStateReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Reference: Internet listener Android example
Android 7.0 (API level 24) placed limitations on broadcasts, as
described in Background Optimization. Android 8.0 (API level 26) makes
these limitations more stringent.
Apps can use Context.registerReceiver() at runtime to register a
receiver for any broadcast, whether implicit or explicit.
Documentation reference.
So, here is a utility class that utilizes a context registered BroadcastReceiver , and LifeCycleObserver for achieving Single-responsibility principle
class ConnectionUtil implements LifecycleObserver {
private ConnectivityManager mConnectivityMgr;
private Context mContext;
private NetworkStateReceiver mNetworkStateReceiver;
interface ConnectionStateListener {
void onAvailable(boolean isAvailable);
}
ConnectionUtil(Context context) {
mContext = context;
mConnectivityMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
((AppCompatActivity) mContext).getLifecycle().addObserver(this);
}
void onInternetStateListener(ConnectionStateListener listener) {
mNetworkStateReceiver = new NetworkStateReceiver(listener);
IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
// Registering the Context Registered Receiver
mContext.registerReceiver(mNetworkStateReceiver, intentFilter);
}
#OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroy() {
// Removing lifecycler owner observer
((AppCompatActivity) mContext).getLifecycle().removeObserver(this);
// Unregistering the Context Registered Receiver
if (mNetworkStateReceiver != null)
mContext.unregisterReceiver(mNetworkStateReceiver);
}
public class NetworkStateReceiver extends BroadcastReceiver {
ConnectionStateListener mListener;
public NetworkStateReceiver(ConnectionStateListener listener) {
mListener = listener;
}
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getExtras() != null) {
NetworkInfo activeNetworkInfo = mConnectivityMgr.getActiveNetworkInfo();
if (activeNetworkInfo != null && activeNetworkInfo.getState() == NetworkInfo.State.CONNECTED) {
// Connected to the internet
mListener.onAvailable(true);
} else if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, Boolean.FALSE)) {
// Not connected to the internet
mListener.onAvailable(false);
}
}
}
}
}
Manifest permission
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Usage:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ConnectionUtil mConnectionMonitor = new ConnectionUtil(this);
mConnectionMonitor.onInternetStateListener(new ConnectionUtil.ConnectionStateListener() {
#Override
public void onAvailable(boolean isAvailable) {
if(isAvailable)
Toast.makeText(MainActivity.this, "Connected", Toast.LENGTH_SHORT).show();
else
Toast.makeText(MainActivity.this, "Disconnected", Toast.LENGTH_SHORT).show();
}
});
}
}
Note: NetworkInfo is deprecated as of API 29, and you can use ConnectivityManager.NetworkCallback with its onAvailable() & onLost() callbacks for the same purpose instead of using a BroadcastReceiver. This answer can guide to target this purpose.

Android event for internet connectivity state change [duplicate]

This question already has answers here:
Check INTENT internet connection
(13 answers)
Closed 4 years ago.
I am making an app where a user is uploading information and files to my server on a somewhat frequent basis. This is done in new threads through a dedicated uploader service.
I know from this thread
Detect whether there is an Internet connection available on Android
that you can check if there is an internet connection relatively easily. You can also get socketTimeoutExceptions to detect internet connectivity issues. All that is well and good, and lets me cache my uploads easily enough when the connection didn't work for whatever reason.
My question though is how do I know when to reattempt the upload? Is there an event triggered when the connection is restored? Or am I stuck making a new thread that sleeps and then checks internet connectivity every 30 seconds or something?
Any ideas would be appreciated!
very old post
but i would like to share my receiver
no need to put your hands on manifest or other boring resources :)
USAGE
YOUR ACTIVITY:
/*
* You need to implement NetworkStateReceiverListener.
* This interface is described inside the NewtworkStateReceiver class
*/
public class MyActivity implements NetworkStateReceiverListener {
/* ... */
private NetworkStateReceiver networkStateReceiver;
}
IN YOUR ACTIVITY: INSTANTIATE THE RECEIVER
public void onCreate(Bundle savedInstanceState) {
/* ... */
networkStateReceiver = new NetworkStateReceiver();
networkStateReceiver.addListener(this);
this.registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
}
public void onDestroy() {
super.onDestroy();
networkStateReceiver.removeListener(this);
this.unregisterReceiver(networkStateReceiver);
}
IN YOUR ACTIVITY: IMPLEMENTS THE REQUIRED METHODS
#Override
public void networkAvailable() {
Log.d("tommydevall", "I'm in, baby!");
/* TODO: Your connection-oriented stuff here */
}
#Override
public void networkUnavailable() {
Log.d("tommydevall", "I'm dancing with myself");
/* TODO: Your disconnection-oriented stuff here */
}
THE RECEIVER
just copy and paste into your project as NetworkStateReceiver.java
public class NetworkStateReceiver extends BroadcastReceiver {
protected Set<NetworkStateReceiverListener> listeners;
protected Boolean connected;
public NetworkStateReceiver() {
listeners = new HashSet<NetworkStateReceiverListener>();
connected = null;
}
public void onReceive(Context context, Intent intent) {
if(intent == null || intent.getExtras() == null)
return;
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = manager.getActiveNetworkInfo();
if(ni != null && ni.getState() == NetworkInfo.State.CONNECTED) {
connected = true;
} else if(intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,Boolean.FALSE)) {
connected = false;
}
notifyStateToAll();
}
private void notifyStateToAll() {
for(NetworkStateReceiverListener listener : listeners)
notifyState(listener);
}
private void notifyState(NetworkStateReceiverListener listener) {
if(connected == null || listener == null)
return;
if(connected == true)
listener.networkAvailable();
else
listener.networkUnavailable();
}
public void addListener(NetworkStateReceiverListener l) {
listeners.add(l);
notifyState(l);
}
public void removeListener(NetworkStateReceiverListener l) {
listeners.remove(l);
}
public interface NetworkStateReceiverListener {
public void networkAvailable();
public void networkUnavailable();
}
}
ENJOY ;)
If you just want to do something simple when the connectivity changes, there is a much easier solution.
In your activity, create a Broadcast Receiver:
private BroadcastReceiver networkStateReceiver=new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = manager.getActiveNetworkInfo();
doSomethingOnNetworkChange(ni);
}
};
Then in onResume and onPause do the registration:
#Override
public void onResume() {
super.onResume();
registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
}
#Override
public void onPause() {
unregisterReceiver(networkStateReceiver);
super.onPause();
}
Not quite sure what was going on in Tommaso's broadcast receiver but it wasn't working for me, here's my implementation. It only notifies on change between connectivity available/unavailable.
Also I register it in onResume() and unregister in onPause(). Otherwise it's the same as above.
public class NetworkStateReceiver extends BroadcastReceiver {
private ConnectivityManager mManager;
private List<NetworkStateReceiverListener> mListeners;
private boolean mConnected;
public NetworkStateReceiver(Context context) {
mListeners = new ArrayList<NetworkStateReceiverListener>();
mManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
checkStateChanged();
}
public void onReceive(Context context, Intent intent) {
if (intent == null || intent.getExtras() == null)
return;
if (checkStateChanged()) notifyStateToAll();
}
private boolean checkStateChanged() {
boolean prev = mConnected;
NetworkInfo activeNetwork = mManager.getActiveNetworkInfo();
mConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
return prev != mConnected;
}
private void notifyStateToAll() {
for (NetworkStateReceiverListener listener : mListeners) {
notifyState(listener);
}
}
private void notifyState(NetworkStateReceiverListener listener) {
if (listener != null) {
if (mConnected) listener.onNetworkAvailable();
else listener.onNetworkUnavailable();
}
}
public void addListener(NetworkStateReceiverListener l) {
mListeners.add(l);
notifyState(l);
}
public void removeListener(NetworkStateReceiverListener l) {
mListeners.remove(l);
}
public interface NetworkStateReceiverListener {
public void onNetworkAvailable();
public void onNetworkUnavailable();
}
}
Android Nougat & O (API 24+) - Network State
Changes mades to #darnmason answer (constructor) to make it work on API 24+.
public NetworkStateReceiver(Context context) {
mListeners = new ArrayList<>();
mManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
context.registerReceiver(NetworkStateReceiver.this, intentFilter);
checkStateChanged();
}

Categories

Resources