本文整理汇总了Java中android.content.Context.CONNECTIVITY_SERVICE属性的典型用法代码示例。如果您正苦于以下问题:Java Context.CONNECTIVITY_SERVICE属性的具体用法?Java Context.CONNECTIVITY_SERVICE怎么用?Java Context.CONNECTIVITY_SERVICE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.content.Context
的用法示例。
在下文中一共展示了Context.CONNECTIVITY_SERVICE属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: observeNetworkConnectivity
@Override public Observable<Connectivity> observeNetworkConnectivity(final Context context) {
final String service = Context.CONNECTIVITY_SERVICE;
final ConnectivityManager manager = (ConnectivityManager) context.getSystemService(service);
networkCallback = createNetworkCallback(context);
registerIdleReceiver(context);
final NetworkRequest request =
new NetworkRequest.Builder().addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
.build();
manager.registerNetworkCallback(request, networkCallback);
return connectivitySubject.toFlowable(BackpressureStrategy.LATEST).doOnCancel(new Action() {
@Override public void run() {
tryToUnregisterCallback(manager);
tryToUnregisterReceiver(context);
}
}).startWith(Connectivity.create(context)).distinctUntilChanged().toObservable();
}
示例2: observeNetworkConnectivity
@Override public Observable<Connectivity> observeNetworkConnectivity(final Context context) {
final String service = Context.CONNECTIVITY_SERVICE;
final ConnectivityManager manager = (ConnectivityManager) context.getSystemService(service);
return Observable.create(new ObservableOnSubscribe<Connectivity>() {
@Override public void subscribe(ObservableEmitter<Connectivity> subscriber) throws Exception {
networkCallback = createNetworkCallback(subscriber, context);
final NetworkRequest networkRequest = new NetworkRequest.Builder().build();
manager.registerNetworkCallback(networkRequest, networkCallback);
}
}).doOnDispose(new Action() {
@Override public void run() {
tryToUnregisterCallback(manager);
}
}).startWith(Connectivity.create(context)).distinctUntilChanged();
}
示例3: getConnectivityManager
private static ConnectivityManager getConnectivityManager(Context context) {
final String service = Context.CONNECTIVITY_SERVICE;
return (ConnectivityManager) context.getSystemService(service);
}
示例4: ConnectivityStub
public ConnectivityStub() {
super(IConnectivityManager.Stub.asInterface, Context.CONNECTIVITY_SERVICE);
}
示例5: ConnectivityPatch
public ConnectivityPatch() {
super(IConnectivityManager.Stub.TYPE, Context.CONNECTIVITY_SERVICE);
}