Skip to content

Commit 3cc5315

Browse files
author
huangjingchao
committed
add mobile type
* newCache/blackVideos: (105 commits) [connectivity] Fix reachability stream for iOS (flutter#2281) [google_sign_in] Port plugin to use the federated Platform Interface (flutter#2266) [webview_flutter] Add async NavigationDelegates (flutter#2257) Update cirrus to create IOS simulator on 13.2 an xCode 11 (flutter#2275) [battery] Update and migrate iOS example project (flutter#2089) [url_launcher] DartDoc and test improvements (flutter#2274) [google_maps_flutter] Define clang module for iOS, fix analyzer warnings (flutter#2182) [video_player] Add v2 embedding support (flutter#2226) [path_provider] Update and migrate iOS example project (flutter#2099) [sensors] Documentation and test improvements (flutter#2272) [image_picker] Lint for public DartDocs (flutter#2270) [connectivity] Lint for public DartDocs (flutter#2269) [shared_preferences] Update and migrate iOS example project (flutter#2103) [quick_actions] Update and migrate iOS example project (flutter#2100) [infra] Ignore analyzer issues in CI (flutter#2271) [android_intent] Add missing DartDocs (flutter#2268) Bump google_maps_flutter pubspec to match CHANGELOG (flutter#2267) [google_sign_in] Handle new style URLs in GoogleUserCircleAvatar (flutter#2252) [google_sign_in] Move plugin to its subdir to allow for federated implementations. Add platform interface. (flutter#2244) Make setMockInitialValues handle non-prefixed keys (flutter#2260) ... # Conflicts: # packages/video_player/CHANGELOG.md # packages/video_player/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayerPlugin.java # packages/video_player/ios/video_player.podspec # packages/video_player/pubspec.yaml # packages/video_player/test/video_player_test.dart
1 parent 509bd31 commit 3cc5315

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

packages/connectivity/android/src/main/java/io/flutter/plugins/connectivity/Connectivity.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import android.net.wifi.WifiInfo;
1212
import android.net.wifi.WifiManager;
1313
import android.os.Build;
14+
import android.telephony.TelephonyManager;
15+
import android.content.Context;
1416

1517
/** Reports connectivity related information such as connectivity type and wifi information. */
1618
class Connectivity {
@@ -34,7 +36,31 @@ String getNetworkType() {
3436
return "wifi";
3537
}
3638
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
37-
return "mobile";
39+
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
40+
int networkType = telephonyManager.getNetworkType();
41+
42+
switch (networkType) {
43+
case TelephonyManager.NETWORK_TYPE_GPRS:
44+
case TelephonyManager.NETWORK_TYPE_CDMA:
45+
case TelephonyManager.NETWORK_TYPE_EDGE:
46+
case TelephonyManager.NETWORK_TYPE_1xRTT:
47+
case TelephonyManager.NETWORK_TYPE_IDEN:
48+
return "2G";
49+
case TelephonyManager.NETWORK_TYPE_EVDO_A:
50+
case TelephonyManager.NETWORK_TYPE_UMTS:
51+
case TelephonyManager.NETWORK_TYPE_EVDO_0:
52+
case TelephonyManager.NETWORK_TYPE_HSDPA:
53+
case TelephonyManager.NETWORK_TYPE_HSUPA:
54+
case TelephonyManager.NETWORK_TYPE_HSPA:
55+
case TelephonyManager.NETWORK_TYPE_EVDO_B:
56+
case TelephonyManager.NETWORK_TYPE_EHRPD:
57+
case TelephonyManager.NETWORK_TYPE_HSPAP:
58+
return "3G";
59+
case TelephonyManager.NETWORK_TYPE_LTE:
60+
return "4G";
61+
default:
62+
return "mobile";
63+
}
3864
}
3965
}
4066

packages/connectivity/ios/Classes/FLTConnectivityPlugin.m

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#import "FLTConnectivityLocationHandler.h"
1111
#import "SystemConfiguration/CaptiveNetwork.h"
1212

13+
#import <CoreTelephony/CTCarrier.h>
14+
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
15+
1316
#include <ifaddrs.h>
1417

1518
#include <arpa/inet.h>
@@ -99,10 +102,26 @@ - (NSString*)statusFromReachability:(Reachability*)reachability {
99102
case ReachableViaWiFi:
100103
return @"wifi";
101104
case ReachableViaWWAN:
102-
return @"mobile";
105+
return [self getMobile];
103106
}
104107
}
105108

109+
- (NSString*)getMobile {
110+
CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
111+
NSString *currentStatus = info.currentRadioAccessTechnology;
112+
NSString *netconnType = @"mobile";
113+
if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyGPRS"] || [currentStatus isEqualToString:@"CTRadioAccessTechnologyEdge"] || [currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMA1x"]) {
114+
netconnType = @"2G";
115+
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyWCDMA"] || [currentStatus isEqualToString:@"CTRadioAccessTechnologyHSDPA"] || [currentStatus isEqualToString:@"CTRadioAccessTechnologyHSUPA"] || [currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORev0"] || [currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORevA"] || [currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORevB"]){
116+
117+
netconnType = @"3G";
118+
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyLTE"]){
119+
netconnType = @"4G";
120+
}
121+
info = nil;
122+
return netconnType;
123+
}
124+
106125
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
107126
if ([call.method isEqualToString:@"check"]) {
108127
// This is supposed to be quick. Another way of doing this would be to

packages/connectivity/lib/connectivity.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ enum ConnectivityResult {
1515

1616
/// Mobile: Device connected to cellular network
1717
mobile,
18+
moblie_4G,
19+
moblie_3G,
20+
moblie_2G,
1821

1922
/// None: Device not connected to any network
2023
none
@@ -229,6 +232,12 @@ ConnectivityResult _parseConnectivityResult(String state) {
229232
return ConnectivityResult.wifi;
230233
case 'mobile':
231234
return ConnectivityResult.mobile;
235+
case '4G':
236+
return ConnectivityResult.moblie_4G;
237+
case '3G':
238+
return ConnectivityResult.moblie_3G;
239+
case '2G':
240+
return ConnectivityResult.moblie_2G;
232241
case 'none':
233242
default:
234243
return ConnectivityResult.none;

0 commit comments

Comments
 (0)