daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Jun 19th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  2. <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  3. <receiver
  4.         android:name=".BroadcastReceiver.NetworkStateReceiver"
  5.         android:enabled="true"
  6.         android:permission="android.permission.ACCESS_NETWORK_STATE"
  7.         tools:ignore="InnerclassSeparator">
  8.         <intent-filter>
  9.             <category android:name="android.intent.category.DEFAULT" />
  10.  
  11.             <action android:name="android.net.conn.CONNECTIVITY_CHANGE"
  12.                 tools:ignore="BatteryLife" />
  13.         </intent-filter>
  14.     </receiver>
  15.    
  16. public class NetworkStateReceiver extends BroadcastReceiver {
  17.  
  18. private ConnectionFirebase connectionFirebase;
  19.  
  20. @Override
  21. public void onReceive(Context context, Intent intent) {
  22.     ConnectivityManager connectivityManager =
  23.             (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
  24.     NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
  25.     onNetworkChange(networkInfo, context);
  26. }
  27.  
  28. private void onNetworkChange(NetworkInfo networkInfo, Context context){
  29.     if (connectionFirebase == null){
  30.         connectionFirebase = new ConnectionFirebase();
  31.     }
  32.     if (networkInfo != null){
  33.         if (networkInfo.getState() == NetworkInfo.State.CONNECTED
  34.                 || networkInfo.getState() == NetworkInfo.State.CONNECTING){
  35.             connectionFirebase.saveNameWifi(context.getApplicationContext());
  36.         }
  37.     }
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top