本文整理匯總了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);
}