本文整理汇总了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;未经允许,请勿转载。 |
请发表评论