存档

文章标签 ‘类型’

android安卓判断JSONArray里面的get(i)的数据类型

2015年10月27日 没有评论

android安卓判断JSONArray里面的get(i)的数据类型:

假设test是从别处读取到的字符串,先将他转换为JSONArray,然后再循环判断

String test = “[1,2,3]”;
try {
JSONArray testA = new JSONArray(test);
for(int i = 0; i < testA.length(); i++) {
Object obj = testA.get(i);
if(obj instanceof String) {
System.out.println(“obj is String”);
} else if(obj instanceof Integer) {
System.out.println(“obj is Integer”);
}
}
System.out.println(testA.length());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

分类: android 标签: , , ,

android安卓获取网络类型

2015年10月22日 没有评论

获取网络类型名称:

public static String getNetworkTypeName(Context context) {
if (context != null) {
ConnectivityManager connectMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectMgr != null) {
NetworkInfo info = connectMgr.getActiveNetworkInfo();
if (info != null) {
switch (info.getType()) {
case ConnectivityManager.TYPE_WIFI:
return “WIFI”;
case ConnectivityManager.TYPE_MOBILE:
return getNetworkTypeName(info.getSubtype());
}
}
}
}
return getNetworkTypeName(TelephonyManager.NETWORK_TYPE_UNKNOWN);
}

public static String getNetworkTypeName(int type) {
switch (type) {
case TelephonyManager.NETWORK_TYPE_GPRS:
return “GPRS”;
case TelephonyManager.NETWORK_TYPE_EDGE:
return “EDGE”;
case TelephonyManager.NETWORK_TYPE_UMTS:
return “UMTS”;
case TelephonyManager.NETWORK_TYPE_HSDPA:
return “HSDPA”;
case TelephonyManager.NETWORK_TYPE_HSUPA:
return “HSUPA”;
case TelephonyManager.NETWORK_TYPE_HSPA:
return “HSPA”;
case TelephonyManager.NETWORK_TYPE_CDMA:
return “CDMA”;
case TelephonyManager.NETWORK_TYPE_EVDO_0:
return “CDMA – EvDo rev. 0”;
case TelephonyManager.NETWORK_TYPE_EVDO_A:
return “CDMA – EvDo rev. A”;
case TelephonyManager.NETWORK_TYPE_EVDO_B:
return “CDMA – EvDo rev. B”;
case TelephonyManager.NETWORK_TYPE_1xRTT:
return “CDMA – 1xRTT”;
case TelephonyManager.NETWORK_TYPE_LTE:
return “LTE”;
case TelephonyManager.NETWORK_TYPE_EHRPD:
return “CDMA – eHRPD”;
case TelephonyManager.NETWORK_TYPE_IDEN:
return “iDEN”;
case TelephonyManager.NETWORK_TYPE_HSPAP:
return “HSPA+”;
default:
return “UNKNOWN”;
}
}

分类: android 标签: , , ,
css.php