本文整理汇总了Java中android.net.ConnectivityManager.TYPE_VPN属性的典型用法代码示例。如果您正苦于以下问题:Java ConnectivityManager.TYPE_VPN属性的具体用法?Java ConnectivityManager.TYPE_VPN怎么用?Java ConnectivityManager.TYPE_VPN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.net.ConnectivityManager
的用法示例。
在下文中一共展示了ConnectivityManager.TYPE_VPN属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNetworkChangeNotifierIsOnline
@UiThreadTest
@MediumTest
@Feature({"Android-AppBase"})
public void testNetworkChangeNotifierIsOnline() throws InterruptedException {
Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
// For any connection type it should return true.
for (int i = ConnectivityManager.TYPE_MOBILE; i < ConnectivityManager.TYPE_VPN; i++) {
mConnectivityDelegate.setActiveNetworkExists(true);
mConnectivityDelegate.setNetworkType(i);
mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
assertTrue(NetworkChangeNotifier.isOnline());
}
mConnectivityDelegate.setActiveNetworkExists(false);
mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
assertFalse(NetworkChangeNotifier.isOnline());
}
示例2: connectionTypeString
private String connectionTypeString(int connectionType) {
switch (connectionType) {
case ConnectivityManager.TYPE_WIFI:
return "Wifi";
case ConnectivityManager.TYPE_BLUETOOTH:
return "Bluetooth";
case ConnectivityManager.TYPE_ETHERNET:
return "Ethernet";
case ConnectivityManager.TYPE_MOBILE:
return "Mobile";
case ConnectivityManager.TYPE_MOBILE_DUN:
return "Mobile dun";
case ConnectivityManager.TYPE_VPN:
return "VPN";
default:
return "Unknown";
}
}
示例3: isMobileConnected
public static boolean isMobileConnected() {
checkInitialization();
ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkInfo info = cm.getActiveNetworkInfo();
return info != null && info.isConnected() &&
(info.getType() == ConnectivityManager.TYPE_MOBILE ||
info.getType() == ConnectivityManager.TYPE_MOBILE_DUN ||
info.getType() == ConnectivityManager.TYPE_VPN);
}
return false;
}
示例4: networkToInfo
@SuppressLint("NewApi")
private NetworkInformation networkToInfo(Network network) {
LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
// getLinkProperties will return null if the network is unknown.
if (linkProperties == null) {
Logging.w(TAG, "Detected unknown network: " + network.toString());
return null;
}
if (linkProperties.getInterfaceName() == null) {
Logging.w(TAG, "Null interface name for network " + network.toString());
return null;
}
NetworkState networkState = getNetworkState(network);
if (networkState.connected && networkState.getNetworkType() == ConnectivityManager.TYPE_VPN) {
// If a VPN network is in place, we can find the underlying network type via querying the
// active network info thanks to
// https://android.googlesource.com/platform/frameworks/base/+/d6a7980d
networkState = getNetworkState();
}
ConnectionType connectionType = getConnectionType(networkState);
if (connectionType == ConnectionType.CONNECTION_NONE) {
// This may not be an error. The OS may signal a network event with connection type
// NONE when the network disconnects.
Logging.d(TAG, "Network " + network.toString() + " is disconnected");
return null;
}
// Some android device may return a CONNECTION_UNKNOWN_CELLULAR or CONNECTION_UNKNOWN type,
// which appears to be usable. Just log them here.
if (connectionType == ConnectionType.CONNECTION_UNKNOWN
|| connectionType == ConnectionType.CONNECTION_UNKNOWN_CELLULAR) {
Logging.d(TAG, "Network " + network.toString() + " connection type is " + connectionType
+ " because it has type " + networkState.getNetworkType() + " and subtype "
+ networkState.getNetworkSubType());
}
NetworkInformation networkInformation =
new NetworkInformation(linkProperties.getInterfaceName(), connectionType,
networkToNetId(network), getIPAddresses(linkProperties));
return networkInformation;
}