本文整理汇总了Java中android.net.NetworkInfo.State.CONNECTING属性的典型用法代码示例。如果您正苦于以下问题:Java State.CONNECTING属性的具体用法?Java State.CONNECTING怎么用?Java State.CONNECTING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.net.NetworkInfo.State
的用法示例。
在下文中一共展示了State.CONNECTING属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNetworkState
public static int getNetworkState(Context context) {
ConnectivityManager connManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
// Wifi
State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.getState();
if (state == State.CONNECTED || state == State.CONNECTING) {
return STATE_WIFI;
}
// 3G
state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
.getState();
if (state == State.CONNECTED || state == State.CONNECTING) {
return STATE_MOBILE;
}
return STATE_DISCONNECT;
}
示例2: getNetworkState
public static int getNetworkState(Context context) {
ConnectivityManager connManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
// Wifi
State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.getState();
if (state == State.CONNECTED || state == State.CONNECTING) {
return NETWORN_WIFI;
}
// 3G
state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
.getState();
if (state == State.CONNECTED || state == State.CONNECTING) {
return NETWORN_MOBILE;
}
return NETWORN_NONE;
}
示例3: getNetworkType
/**
* @param context Context
* @return 1-wifi, 2-3G, 0-无网络连接
*/
public static int getNetworkType(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
State mobileState = connectivityManager.getNetworkInfo(
ConnectivityManager.TYPE_MOBILE).getState();
State wifiState = connectivityManager.getNetworkInfo(
ConnectivityManager.TYPE_WIFI).getState();
if (wifiState == State.CONNECTED || wifiState == State.CONNECTING) {
return 1;
} else if (mobileState == State.CONNECTED
|| mobileState == State.CONNECTING) {
return 2;
} else {
return 0;
}
}
示例4: getDataConnectionState
public static int getDataConnectionState(Context context) {
if (!isSimInstalled(context)) {
return NETWORK_UTILS_CONNECTION_STATE_DISCONNECTED;
}
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
for (NetworkInfo info : manager.getAllNetworkInfo()) {
if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
if (info.getState() == State.CONNECTED) {
return NETWORK_UTILS_CONNECTION_STATE_CONNECTED;
} else if (info.getState() == State.DISCONNECTED) {
return NETWORK_UTILS_CONNECTION_STATE_DISCONNECTED;
} else if (info.getState() == State.CONNECTING) {
return NETWORK_UTILS_CONNECTION_STATE_CONNECTING;
} else if (info.getState() == State.DISCONNECTING) {
return NETWORK_UTILS_CONNECTION_STATE_DISCONNECTED;
} else if (info.getState() == State.SUSPENDED) {
return NETWORK_UTILS_CONNECTION_STATE_SUSPENDED;
} else if (info.getState() == State.UNKNOWN) {
return NETWORK_UTILS_CONNECTION_STATE_UNKNOWN;
}
}
}
return NETWORK_UTILS_CONNECTION_STATE_DISCONNECTED;
}
示例5: getNetworkState
/**
* 获取当前网络状态
* @param context
* @return
*/
public static int getNetworkState(Context context) {
ConnectivityManager connManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
// Wifi
State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.getState();
if (state == State.CONNECTED || state == State.CONNECTING) {
return NETWORN_WIFI;
}
// 3G
state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
.getState();
if (state == State.CONNECTED || state == State.CONNECTING) {
return NETWORN_MOBILE;
}
return NETWORN_NONE;
}
示例6: onReceive
public void onReceive(Context c, Intent intent) {
NetworkInfo wifiNetworkInfo = (NetworkInfo) intent
.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
Log.v(TAG, "mWifiNetworkInfo: " + wifiNetworkInfo.toString());
if (wifiNetworkInfo.getState() == State.CONNECTED) {
log.setText("Connected to: "
+ wifiManager.getConnectionInfo().getSSID());
if (wifiManager != null
&& wifiManager.getConnectionInfo() != null
&& wifiManager.getConnectionInfo().getSSID() != null
&& !wifiManager.getConnectionInfo().getSSID()
.equals(wifiSSID)) {
Log.v(TAG, wifiManager.getConnectionInfo().getSSID());
refreshWifi();
}
} else if (wifiNetworkInfo.getState() == State.CONNECTING) {
log.setText("Connecting...");
} else if (wifiNetworkInfo.getState() == State.DISCONNECTING) {
log.setText("Disconnecting...");
} else if (wifiNetworkInfo.getState() == State.DISCONNECTED) {
log.setText("Disconnected");
}
}
示例7: checkNetworkState
/**
* ���������
*/
private void checkNetworkState() {
State gprs = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
State wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
// �ж�Ϊgprs״̬
if (gprs == State.CONNECTED || gprs == State.CONNECTING) {
tv_network_on.setText("���������ӣ�GPRS");
}
// �ж�Ϊwifi״̬
if (wifi == State.CONNECTED || wifi == State.CONNECTING) {
tv_network_on.setText("���������ӣ�WIFI");
}
}
示例8: isWifi
public boolean isWifi() {
// TODO Auto-generated method stub
if(checkNetwork()){
State wifi = con.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
//判断wifi已连接的条件
if(wifi == State.CONNECTED||wifi==State.CONNECTING){
return true;
}
return false;
}
return false;
}
示例9: isWiFi
/**
* 只是判断WIFI
*
* @param context 上下文
* @return 是否打开Wifi
*/
public static boolean isWiFi(Context context) {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
State wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.getState();
if (wifi == State.CONNECTED || wifi == State.CONNECTING)
return true;
return false;
}
示例10: getWifiStatus
public static String getWifiStatus(Context context) {
String wifiStatus = "";
ConnectivityManager conMan = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.getState();
WifiManager wifiManager = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String ssid = wifiInfo.getSSID();
if (wifi == State.CONNECTED) {
wifiStatus = "无线网络已连接, " + "SSID: " + ssid;
} else if (wifi == State.CONNECTING) {
wifiStatus = "无线网络正在连接, " + "SSID: " + ssid;
} else if (wifi == State.DISCONNECTED) {
wifiStatus = "无线网络已断开";
} else if (wifi == State.DISCONNECTING) {
wifiStatus = "无线网络正在断开, " + "SSID: " + ssid;
} else if (wifi == State.SUSPENDED) {
wifiStatus = "无线网络挂起";
} else if (wifi == State.UNKNOWN) {
wifiStatus = "无线网络未连接";
}
return wifiStatus;
}
示例11: isNetworkAvailable
/**
* 网络已经连接,然后去判断是wifi连接还是GPRS连接 设置逻辑调用
*/
private void isNetworkAvailable() {
State gprs = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
.getState();
State wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.getState();
// GPRS,流量状态下,拷贝数据库
if (gprs == State.CONNECTED || gprs == State.CONNECTING) {
Toast.makeText(this, "gprs(流量)状态下,copy初始数据~~", Toast.LENGTH_SHORT)
.show();
Boolean copyDatabase = new CopyDbToSdcard(getApplicationContext())
.copyDatabase();
copyFileOrLoad(copyDatabase);
}
// 判断为wifi状态下才加载地区数据,否则不加载
if (wifi == State.CONNECTED || wifi == State.CONNECTING) {
// 没有数据的时候初始化一个dialog做初始化操作用
dialog = new ProgressDialog(MainActivity.this);
// 设置进度条风格,风格为圆形,旋转的
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
// 设置ProgressDialog 提示信息
dialog.setMessage("正在初始化数据,请稍候...");
// 设置ProgressDialog 标题图标
// m_pDialog.setIcon(R.drawable.icon);
// 设置ProgressDialog 的进度条是否不明确
dialog.setIndeterminate(false);
// 设置ProgressDialog 是否可以按退回按键取消
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.show();
Toast.makeText(getApplicationContext(), "Wifi状态下,数据录入准备~请稍等...",
Toast.LENGTH_LONG).show();
new GetAreaDataSaveDB(getApplicationContext(),
MainActivity.this.dialog);
initLocation();
}
}
示例12: isWifiAvailable
private boolean isWifiAvailable() {
Context context = ZenApplication.getAppContext();
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
State wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.getState();
if(wifi == State.CONNECTED || wifi == State.CONNECTING) {
System.out.println("wifi available");
return true;
}
return false;
}
示例13: setNetworkConnection
public void setNetworkConnection(Context context) {
this.currentContext = context;
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo == null) {
VoiceApi.makeToastShort(currentContext, "无网络连接");
return;
}
switch (networkInfo.getType()) {
case ConnectivityManager.TYPE_WIFI:
VoiceApi.makeToastShort(context, "WIFI Connection");
break;
case ConnectivityManager.TYPE_MOBILE:
VoiceApi.makeToastShort(context, "MOBILE Connection");
break;
default:
VoiceApi.makeToastShort(context, "Unknown Connection");
break;
}
boolean available = networkInfo.isAvailable();
if (available) {
VoiceApi.makeToastShort(context,
"Current Connectivity is Available");
} else {
VoiceApi.makeToastShort(context,
"Current Connectivity is not Available");
}
State state = connectivityManager.getNetworkInfo(
ConnectivityManager.TYPE_MOBILE).getState();
if (State.CONNECTED == state) {
VoiceApi.makeToastShort(context, "GPRS Connected");
} else if (State.CONNECTING == state) {
VoiceApi.makeToastShort(context, "GPRS Connecting");
} else if (State.DISCONNECTING == state) {
VoiceApi.makeToastShort(context, "GPRS Disconnecting");
} else if (State.DISCONNECTED == state) {
VoiceApi.makeToastShort(context, "GPRS Disconnected");
} else {
VoiceApi.makeToastShort(context, "Other GPRS State");
}
state = connectivityManager.getNetworkInfo(
ConnectivityManager.TYPE_WIFI).getState();
if (State.CONNECTED == state) {
VoiceApi.makeToastShort(context, "WIFI Connected");
} else if (State.CONNECTING == state) {
VoiceApi.makeToastShort(context, "WIFI Connecting");
} else if (State.DISCONNECTING == state) {
VoiceApi.makeToastShort(context, "WIFI Disconnecting");
} else if (State.DISCONNECTED == state) {
VoiceApi.makeToastShort(context, "WIFI Disconnected");
} else {
VoiceApi.makeToastShort(context, "Other WIFI State");
}
context.startActivity(new Intent(
android.provider.Settings.ACTION_WIRELESS_SETTINGS));
}