• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java NetworkCallback类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中android.net.ConnectivityManager.NetworkCallback的典型用法代码示例。如果您正苦于以下问题:Java NetworkCallback类的具体用法?Java NetworkCallback怎么用?Java NetworkCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NetworkCallback类属于android.net.ConnectivityManager包,在下文中一共展示了NetworkCallback类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testConnectivityManagerDelegateDoesNotCrash

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
@UiThreadTest
@MediumTest
@Feature({"Android-AppBase"})
public void testConnectivityManagerDelegateDoesNotCrash() {
    ConnectivityManagerDelegate delegate =
            new ConnectivityManagerDelegate(getInstrumentation().getTargetContext());
    delegate.getNetworkState();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // getNetworkState(Network) doesn't crash upon invalid Network argument.
        Network invalidNetwork = netIdToNetwork(NetId.INVALID);
        NetworkState invalidNetworkState = delegate.getNetworkState(invalidNetwork);
        assertFalse(invalidNetworkState.isConnected());
        assertEquals(-1, invalidNetworkState.getNetworkType());
        assertEquals(-1, invalidNetworkState.getNetworkSubType());

        Network[] networks = delegate.getAllNetworksUnfiltered();
        if (networks.length >= 1) {
            delegate.getNetworkState(networks[0]);
        }
        delegate.getDefaultNetId();
        NetworkCallback networkCallback = new NetworkCallback();
        NetworkRequest networkRequest = new NetworkRequest.Builder().build();
        delegate.registerNetworkCallback(networkRequest, networkCallback);
        delegate.unregisterNetworkCallback(networkCallback);
    }
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:27,代码来源:NetworkChangeNotifierTest.java


示例2: shouldRegisterWithDefaultNetworkRequest

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
@Test()
public void shouldRegisterWithDefaultNetworkRequest() {
  NetworkRequest defaultRequest = new NetworkRequest.Builder().build();
  ConnectivityManager manager = setUpManagerWithNetworkRequest(null);

  sut.observe().subscribeWith(testObserver).assertSubscribed();

  verify(manager).registerNetworkCallback(eq(defaultRequest), any(NetworkCallback.class));
}
 
开发者ID:greyfoxit,项目名称:RxNetwork,代码行数:10,代码来源:LollipopNetworkObservingStrategyTest.java


示例3: registerNetworkCallback

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
private void registerNetworkCallback(Context context) {
  final ConnectivityManager manager =
      (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
  manager.registerNetworkCallback(
      new NetworkRequest.Builder()
          .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
          .addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET)
          .build(),
      new NetworkCallback() {
        @Override
        public void onAvailable(Network network) {
          mSambaClient.reset();
        }
      });
}
 
开发者ID:google,项目名称:samba-documents-provider,代码行数:16,代码来源:SambaProviderApplication.java


示例4: networkCallback

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
@TargetApi(LOLLIPOP)
NetworkCallback networkCallback(final String networkSSID,
                                final NetworkStateChangeListener listener) {
    return new NetworkCallback() {
        @Override
        public void onAvailable(Network network) {
            NetworkInfo networkInfo = manager.getNetworkInfo(network);
            logger.i("Network is Available. Network Info: " + networkInfo);

            if (WifiHelper.areEqual(networkInfo.getExtraInfo(), networkSSID)) {
                manager.unregisterNetworkCallback(this);
                networkCallback = null;
                bindToRequiredNetwork(network);
                logger.i(format("Bound application to use %s network", networkSSID));
                listener.onNetworkBound();
            }
        }
    };
}
 
开发者ID:nishkarsh,项目名称:android-wificonnect,代码行数:20,代码来源:WifiUtil.java


示例5: registerNetworkCallback

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
/** Only callable on Lollipop and newer releases. */
@SuppressLint("NewApi")
public void registerNetworkCallback(NetworkCallback networkCallback) {
  connectivityManager.registerNetworkCallback(
      new NetworkRequest.Builder()
          .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
          .build(),
      networkCallback);
}
 
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:10,代码来源:NetworkMonitorAutoDetect.java


示例6: requestMobileNetwork

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
/** Only callable on Lollipop and newer releases. */
@SuppressLint("NewApi")
public void requestMobileNetwork(NetworkCallback networkCallback) {
  NetworkRequest.Builder builder = new NetworkRequest.Builder();
  builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
      .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
  connectivityManager.requestNetwork(builder.build(), networkCallback);
}
 
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:9,代码来源:NetworkMonitorAutoDetect.java


示例7: releaseCallback

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
@SuppressLint("NewApi")
public void releaseCallback(NetworkCallback networkCallback) {
  if (supportNetworkCallback()) {
    Logging.d(TAG, "Unregister network callback");
    connectivityManager.unregisterNetworkCallback(networkCallback);
  }
}
 
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:8,代码来源:NetworkMonitorAutoDetect.java


示例8: NetworkMonitorAutoDetect

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
/**
 * Constructs a NetworkMonitorAutoDetect. Should only be called on UI thread.
 */
@SuppressLint("NewApi")
public NetworkMonitorAutoDetect(Observer observer, Context context) {
  this.observer = observer;
  this.context = context;
  connectivityManagerDelegate = new ConnectivityManagerDelegate(context);
  wifiManagerDelegate = new WifiManagerDelegate(context);

  final NetworkState networkState = connectivityManagerDelegate.getNetworkState();
  connectionType = getConnectionType(networkState);
  wifiSSID = getWifiSSID(networkState);
  intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);

  if (PeerConnectionFactory.fieldTrialsFindFullName("IncludeWifiDirect").equals("Enabled")) {
    wifiDirectManagerDelegate = new WifiDirectManagerDelegate(observer, context);
  }

  registerReceiver();
  if (connectivityManagerDelegate.supportNetworkCallback()) {
    // On Android 6.0.0, the WRITE_SETTINGS permission is necessary for
    // requestNetwork, so it will fail. This was fixed in Android 6.0.1.
    NetworkCallback tempNetworkCallback = new NetworkCallback();
    try {
      connectivityManagerDelegate.requestMobileNetwork(tempNetworkCallback);
    } catch (java.lang.SecurityException e) {
      Logging.w(TAG, "Unable to obtain permission to request a cellular network.");
      tempNetworkCallback = null;
    }
    mobileNetworkCallback = tempNetworkCallback;
    allNetworkCallback = new SimpleNetworkCallback();
    connectivityManagerDelegate.registerNetworkCallback(allNetworkCallback);
  } else {
    mobileNetworkCallback = null;
    allNetworkCallback = null;
  }
}
 
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:39,代码来源:NetworkMonitorAutoDetect.java


示例9: NetworkMonitorAutoDetect

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
/**
 * Constructs a NetworkMonitorAutoDetect. Should only be called on UI thread.
 */
@SuppressLint("NewApi")
public NetworkMonitorAutoDetect(Observer observer, Context context) {
  this.observer = observer;
  this.context = context;
  connectivityManagerDelegate = new ConnectivityManagerDelegate(context);
  wifiManagerDelegate = new WifiManagerDelegate(context);

  final NetworkState networkState = connectivityManagerDelegate.getNetworkState();
  connectionType = getConnectionType(networkState);
  wifiSSID = getWifiSSID(networkState);
  intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);

  registerReceiver();
  if (connectivityManagerDelegate.supportNetworkCallback()) {
    // On Android 6.0.0, the WRITE_SETTINGS permission is necessary for
    // requestNetwork, so it will fail. This was fixed in Android 6.0.1.
    NetworkCallback tempNetworkCallback = new NetworkCallback();
    try {
      connectivityManagerDelegate.requestMobileNetwork(tempNetworkCallback);
    } catch (java.lang.SecurityException e) {
      Logging.w(TAG, "Unable to obtain permission to request a cellular network.");
      tempNetworkCallback = null;
    }
    mobileNetworkCallback = tempNetworkCallback;
    allNetworkCallback = new SimpleNetworkCallback();
    connectivityManagerDelegate.registerNetworkCallback(allNetworkCallback);
  } else {
    mobileNetworkCallback = null;
    allNetworkCallback = null;
  }
}
 
开发者ID:lgyjg,项目名称:AndroidRTC,代码行数:35,代码来源:NetworkMonitorAutoDetect.java


示例10: registerNetworkCallback

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
@Implementation(minSdk = LOLLIPOP)
@RequiresApi(LOLLIPOP)
public void registerNetworkCallback(NetworkRequest request, NetworkCallback networkCallback) {
  networkCallbacks.add(networkCallback);
  // simulate available connection
  networkCallback.onAvailable(getActiveNetwork());
}
 
开发者ID:greyfoxit,项目名称:RxNetwork,代码行数:8,代码来源:ShadowConnectivityManagerWithCallback.java


示例11: unregisterNetworkCallback

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
@RequiresApi(LOLLIPOP)
@Implementation(minSdk = LOLLIPOP)
public void unregisterNetworkCallback(NetworkCallback networkCallback) {
  if (networkCallback == null) {
    throw new IllegalArgumentException("Invalid NetworkCallback");
  }
  if (networkCallbacks.contains(networkCallback)) {
    networkCallbacks.remove(networkCallback);
    // simulate lost connection
    networkCallback.onLost(getActiveNetwork());
  }
}
 
开发者ID:greyfoxit,项目名称:RxNetwork,代码行数:13,代码来源:ShadowConnectivityManagerWithCallback.java


示例12: shouldRegisterWithCustomNetworkRequest

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
@Test()
public void shouldRegisterWithCustomNetworkRequest() {
  NetworkRequest customRequest =
      new NetworkRequest.Builder().addTransportType(TRANSPORT_WIFI).build();
  ConnectivityManager manager = setUpManagerWithNetworkRequest(customRequest);

  sut.observe().subscribeWith(testObserver).assertSubscribed();

  verify(manager).registerNetworkCallback(eq(customRequest), any(NetworkCallback.class));
}
 
开发者ID:greyfoxit,项目名称:RxNetwork,代码行数:11,代码来源:LollipopNetworkObservingStrategyTest.java


示例13: shouldDisposeWithException_whenObserverDisposed

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
@Test
public void shouldDisposeWithException_whenObserverDisposed() {
  ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
  doReturn(connectivityManager).when(context).getSystemService(CONNECTIVITY_SERVICE);
  doThrow(Exception.class).when(connectivityManager)
      .unregisterNetworkCallback(any(NetworkCallback.class));
  sut = spy(new LollipopNetworkObservingStrategy(context));

  sut.observe().subscribeWith(testObserver).assertSubscribed();
  testObserver.dispose();

  verify(sut).dispose();
  verify(sut).onError(anyString(), any(Exception.class));
  testObserver.isDisposed();
}
 
开发者ID:greyfoxit,项目名称:RxNetwork,代码行数:16,代码来源:LollipopNetworkObservingStrategyTest.java


示例14: setupNetworkCallbackUnregisterException

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
private void setupNetworkCallbackUnregisterException() {
  ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
  doReturn(connectivityManager).when(context).getSystemService(Context.CONNECTIVITY_SERVICE);
  doThrow(Exception.class).when(connectivityManager)
      .unregisterNetworkCallback(any(NetworkCallback.class));

  sut = spy(new MarshmallowNetworkObservingStrategy(context));
}
 
开发者ID:greyfoxit,项目名称:RxNetwork,代码行数:9,代码来源:MarshmallowNetworkObservingStrategyTest.java


示例15: a

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
public final void a()
{
  if (!this.h) {}
  do
  {
    return;
    this.c.unregisterReceiver(this);
    this.h = false;
  } while (this.f == null);
  rja localrja = this.e;
  ConnectivityManager.NetworkCallback localNetworkCallback = this.f;
  localrja.a.unregisterNetworkCallback(localNetworkCallback);
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:14,代码来源:NetworkChangeNotifierAutoDetect.java


示例16: a

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
protected final void a()
{
  NetworkChangeNotifierAutoDetect localNetworkChangeNotifierAutoDetect = this.a;
  if (!localNetworkChangeNotifierAutoDetect.h)
  {
    rjh localrjh = rja.a(localNetworkChangeNotifierAutoDetect.e.a.getActiveNetworkInfo());
    localNetworkChangeNotifierAutoDetect.c(localrjh);
    localNetworkChangeNotifierAutoDetect.d(localrjh);
    localNetworkChangeNotifierAutoDetect.c.registerReceiver(localNetworkChangeNotifierAutoDetect, localNetworkChangeNotifierAutoDetect.a);
    localNetworkChangeNotifierAutoDetect.h = true;
    if (localNetworkChangeNotifierAutoDetect.f != null)
    {
      rja localrja = localNetworkChangeNotifierAutoDetect.e;
      NetworkRequest localNetworkRequest = localNetworkChangeNotifierAutoDetect.g;
      ConnectivityManager.NetworkCallback localNetworkCallback = localNetworkChangeNotifierAutoDetect.f;
      localrja.a.registerNetworkCallback(localNetworkRequest, localNetworkCallback);
      Network[] arrayOfNetwork = localNetworkChangeNotifierAutoDetect.e.a.getAllNetworks();
      int[] arrayOfInt = new int[arrayOfNetwork.length];
      for (int i = 0; i < arrayOfNetwork.length; i++) {
        arrayOfInt[i] = Integer.parseInt(arrayOfNetwork[i].toString());
      }
      localNetworkChangeNotifierAutoDetect.b.a(arrayOfInt);
    }
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:26,代码来源:NetworkChangeNotifierAutoDetect$RegistrationPolicy.java


示例17: registerNetworkCallback

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
/**
 * Registers networkCallback to receive notifications about networks
 * that satisfy networkRequest.
 * Only callable on Lollipop and newer releases.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void registerNetworkCallback(
        NetworkRequest networkRequest, NetworkCallback networkCallback) {
    mConnectivityManager.registerNetworkCallback(networkRequest, networkCallback);
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:11,代码来源:NetworkChangeNotifierAutoDetect.java


示例18: unregisterNetworkCallback

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
/**
 * Unregisters networkCallback from receiving notifications.
 * Only callable on Lollipop and newer releases.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void unregisterNetworkCallback(NetworkCallback networkCallback) {
    mConnectivityManager.unregisterNetworkCallback(networkCallback);
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:9,代码来源:NetworkChangeNotifierAutoDetect.java


示例19: unregisterNetworkCallback

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
@Override
public void unregisterNetworkCallback(NetworkCallback networkCallback) {}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:3,代码来源:NetworkChangeNotifierTest.java


示例20: registerNetworkCallback

import android.net.ConnectivityManager.NetworkCallback; //导入依赖的package包/类
@Override
public void registerNetworkCallback(
        NetworkRequest networkRequest, NetworkCallback networkCallback) {
    mLastRegisteredNetworkCallback = networkCallback;
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:6,代码来源:NetworkChangeNotifierTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AnnotationMirror类代码示例发布时间:2022-05-22
下一篇:
Java UpdateParameterInfoContext类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap