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

Java ShadowConnectivityManager类代码示例

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

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



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

示例1: setNetworkInfo

import org.robolectric.shadows.ShadowConnectivityManager; //导入依赖的package包/类
public static void setNetworkInfo(Context context, boolean isConnected, boolean isRoaming, boolean isWifi) {
    ShadowConnectivityManager manager =
            shadowOf((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
    NetworkInfo.DetailedState detailedState =
            isConnected ? NetworkInfo.DetailedState.CONNECTED : NetworkInfo.DetailedState.DISCONNECTED;
    int type = isConnected ? (isWifi ? ConnectivityManager.TYPE_WIFI : ConnectivityManager.TYPE_MOBILE) : -1;
    NetworkInfo networkInfo =
            ShadowNetworkInfo.newInstance(detailedState, type, 0, isConnected, isConnected, isRoaming);
    manager.setActiveNetworkInfo(networkInfo);
}
 
开发者ID:Doist,项目名称:JobSchedulerCompat,代码行数:11,代码来源:DeviceTestUtils.java


示例2: toggleNetwork

import org.robolectric.shadows.ShadowConnectivityManager; //导入依赖的package包/类
private void toggleNetwork(int networkType, NetworkInfo.DetailedState detailedState) {
    NetworkInfo networkInfo = null;
    switch (detailedState) {
        case CONNECTED:
            networkInfo = ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, networkType, 0, true, true);
            break;
        case DISCONNECTED:
            networkInfo = ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.DISCONNECTED, networkType, 0, true, false);
            break;
    }

    ConnectivityManager cmMock = (ConnectivityManager) RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE);
    ShadowConnectivityManager shadowConnectivityManager = shadowOf(cmMock);

    shadowConnectivityManager.setNetworkInfo(networkType, networkInfo);
    shadowConnectivityManager.setActiveNetworkInfo(shadowConnectivityManager.getNetworkInfo(networkType));
}
 
开发者ID:openwebnet,项目名称:openwebnet-android,代码行数:18,代码来源:UtilityServiceTest.java


示例3: connectToNetwork

import org.robolectric.shadows.ShadowConnectivityManager; //导入依赖的package包/类
@Before
public void connectToNetwork() {
    ShadowConnectivityManager shadowConnectivityManager = Shadows.shadowOf(
            (ConnectivityManager) RuntimeEnvironment.application
                    .getSystemService(Context.CONNECTIVITY_SERVICE));
    shadowConnectivityManager.setNetworkInfo(ConnectivityManager.TYPE_MOBILE,
            ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED,
                    ConnectivityManager.TYPE_MOBILE, ConnectivityManager.TYPE_MOBILE_MMS,
                    true, false));
    // Set the default network to WiFi, as downloads are always allowed over
    // WiFi regardless of the configuration settings.
    shadowConnectivityManager.setActiveNetworkInfo(
            ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.DISCONNECTED,
                    ConnectivityManager.TYPE_WIFI, 0, true, true));
}
 
开发者ID:edx,项目名称:edx-app-android,代码行数:16,代码来源:UiTest.java


示例4: setup

import org.robolectric.shadows.ShadowConnectivityManager; //导入依赖的package包/类
@Override
public void setup() {
    super.setup();
    connectivityManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    // Not using Shadows.shadowOf(connectivityManager) because of Robolectric bug when using API23+
    // See: https://github.com/robolectric/robolectric/issues/1862
    shadowConnectivityManager = (ShadowConnectivityManager) ShadowExtractor.extract(connectivityManager);
}
 
开发者ID:appnexus,项目名称:mobile-sdk-android,代码行数:9,代码来源:BannerImpressionTests.java


示例5: disconnectFromNetwork

import org.robolectric.shadows.ShadowConnectivityManager; //导入依赖的package包/类
public void disconnectFromNetwork() {
    ShadowConnectivityManager shadowConnectivityManager = Shadows.shadowOf(
            (ConnectivityManager) RuntimeEnvironment.application
                    .getSystemService(Context.CONNECTIVITY_SERVICE));
    shadowConnectivityManager.setActiveNetworkInfo(null);
}
 
开发者ID:edx,项目名称:edx-app-android,代码行数:7,代码来源:UiTest.java


示例6: shadowOf

import org.robolectric.shadows.ShadowConnectivityManager; //导入依赖的package包/类
public static ShadowConnectivityManager shadowOf(ConnectivityManager instance) {
  return (ShadowConnectivityManager) shadowOf_(instance);
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:4,代码来源:Robolectric.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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