当前位置: 首页>>代码示例>>Java>>正文


Java Context.CONNECTIVITY_SERVICE属性代码示例

本文整理汇总了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();
}
 
开发者ID:datalink747,项目名称:Rx_java2_soussidev,代码行数:21,代码来源:MarshmallowNetworkObservingStrategy.java

示例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();
}
 
开发者ID:datalink747,项目名称:Rx_java2_soussidev,代码行数:16,代码来源:LollipopNetworkObservingStrategy.java

示例3: getConnectivityManager

private static ConnectivityManager getConnectivityManager(Context context) {
    final String service = Context.CONNECTIVITY_SERVICE;
    return (ConnectivityManager) context.getSystemService(service);
}
 
开发者ID:datalink747,项目名称:Rx_java2_soussidev,代码行数:4,代码来源:Connectivity.java

示例4: ConnectivityStub

public ConnectivityStub() {
    super(IConnectivityManager.Stub.asInterface, Context.CONNECTIVITY_SERVICE);
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:3,代码来源:ConnectivityStub.java

示例5: ConnectivityPatch

public ConnectivityPatch() {
    super(IConnectivityManager.Stub.TYPE, Context.CONNECTIVITY_SERVICE);
}
 
开发者ID:codehz,项目名称:container,代码行数:3,代码来源:ConnectivityPatch.java


注:本文中的android.content.Context.CONNECTIVITY_SERVICE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。