我无法实现rxJava以检查android上是否有互联网连接我这样做:
在我的启动器活动中,我在onCreate中有这个:
AndroidObservable.bindActivity(this,
Observable.just(Utils.isActiveInternetConnection(Launcher.this)))
.subscribeOn(Schedulers.newThread())
.subscribe(new Action1<Boolean>() {
@Override
public void call(Boolean aBoolean) {
if (aBoolean) {
Toast.makeText(Launcher.this, "There is internet connection", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Launcher.this, "There is no internet connection", Toast.LENGTH_SHORT).show();
}
}
});
Run Code Online (Sandbox Code Playgroud)
我有一个Utils类,它是一个带有静态方法的final类,observable使用的方法是这样的:
public static boolean isActiveInternetConnection(Context context) {
if (isNetworkAvailable(context)) {
try {
HttpURLConnection urlc = (HttpURLConnection) (new URL("http://www.google.com").openConnection());
urlc.setRequestProperty("User-Agent", "Test");
urlc.setRequestProperty("Connection", "close");
urlc.setConnectTimeout(1500);
urlc.connect();
return (urlc.getResponseCode() == 200);
} catch (IOException e) {
Log.e("network", "Error checking internet connection", e);
}
} else {
Log.d("network", …Run Code Online (Sandbox Code Playgroud) 我正在尝试用android上的recyclerview实现类似coverflow的东西,但我找不到这样做的方法(已在谷歌上搜索过).
我知道有这个库https://github.com/davidschreiber/FancyCoverFlow但不再维护,发布者说我们可以用recyclerview实现这种行为,有人能指出我正确的方向吗?谢谢.