获取手机型号: android.os.build.model
获取手机的sdk版本号:android.os.build.version.sdk
获取手机当前网络类型代码如下:这是一个工具类,大家可以保存下来以后方便使用。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
package com.iqtogether.qxueyou.support.util; import android.content.context; import android.net.connectivitymanager; import android.net.networkinfo; import android.telephony.telephonymanager; /** * 获取网络连接的工具类 * created by chengguo on 2016/3/17. */ public class intenetutil { //没有网络连接 public static final int networn_none = 0 ; //wifi连接 public static final int networn_wifi = 1 ; //手机网络数据连接类型 public static final int networn_2g = 2 ; public static final int networn_3g = 3 ; public static final int networn_4g = 4 ; public static final int networn_mobile = 5 ; /** * 获取当前网络连接类型 * @param context * @return */ public static int getnetworkstate(context context) { //获取系统的网络服务 connectivitymanager connmanager = (connectivitymanager) context.getsystemservice(context.connectivity_service); //如果当前没有网络 if ( null == connmanager) return networn_none; //获取当前网络类型,如果为空,返回无网络 networkinfo activenetinfo = connmanager.getactivenetworkinfo(); if (activenetinfo == null || !activenetinfo.isavailable()) { return networn_none; } // 判断是不是连接的是不是wifi networkinfo wifiinfo = connmanager.getnetworkinfo(connectivitymanager.type_wifi); if ( null != wifiinfo) { networkinfo.state state = wifiinfo.getstate(); if ( null != state) if (state == networkinfo.state.connected || state == networkinfo.state.connecting) { return networn_wifi; } } // 如果不是wifi,则判断当前连接的是运营商的哪种网络2g、3g、4g等 networkinfo networkinfo = connmanager.getnetworkinfo(connectivitymanager.type_mobile); if ( null != networkinfo) { networkinfo.state state = networkinfo.getstate(); string strsubtypename = networkinfo.getsubtypename(); if ( null != state) if (state == networkinfo.state.connected || state == networkinfo.state.connecting) { switch (activenetinfo.getsubtype()) { //如果是2g类型 case telephonymanager.network_type_gprs: // 联通2g case telephonymanager.network_type_cdma: // 电信2g case telephonymanager.network_type_edge: // 移动2g case telephonymanager.network_type_1xrtt: case telephonymanager.network_type_iden: return networn_2g; //如果是3g类型 case telephonymanager.network_type_evdo_a: // 电信3g case telephonymanager.network_type_umts: case telephonymanager.network_type_evdo_0: case telephonymanager.network_type_hsdpa: case telephonymanager.network_type_hsupa: case telephonymanager.network_type_hspa: case telephonymanager.network_type_evdo_b: case telephonymanager.network_type_ehrpd: case telephonymanager.network_type_hspap: return networn_3g; //如果是4g类型 case telephonymanager.network_type_lte: return networn_4g; default : //中国移动 联通 电信 三种3g制式 if (strsubtypename.equalsignorecase( "td-scdma" ) || strsubtypename.equalsignorecase( "wcdma" ) || strsubtypename.equalsignorecase( "cdma2000" )) { return networn_3g; } else { return networn_mobile; } } } } return networn_none; } } |
以上内容是小编给大家介绍的android获取当前手机网络类型(2g、3g、4g、wifi)以及手机型号、版本号的全部叙述,希望对大家有所帮助!