Created
December 2, 2015 15:58
-
-
Save TechIsFun/bf0c5acab36690f226d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public Observable<Intent> networkObservable() { | |
| return Observable.create(new Observable.OnSubscribe<Intent>() { | |
| @Override | |
| public void call(Subscriber<? super Intent> subscriber) { | |
| final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { | |
| @Override | |
| public void onReceive(Context context, Intent intent) { | |
| subscriber.onNext(intent); | |
| } | |
| }; | |
| final Subscription subscription = Subscriptions.create(new Action0() { | |
| @Override | |
| public void call() { | |
| mContext.unregisterReceiver(broadcastReceiver); | |
| } | |
| }); | |
| subscriber.add(subscription); | |
| mContext.registerReceiver(broadcastReceiver, mIntentFilter); | |
| } | |
| }); | |
| } | |
| private boolean isNetworkAvailable() { | |
| ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); | |
| NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); | |
| return activeNetwork != null; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment